The OP's original code was actually all valid SPSS code. Input programs are rarely used any more as input sources tend to be different from the past, but they are still valid SPSS code.
--
Original Message:
Sent: 6/23/2023 2:20:00 PM
From: Youssef Sbai Idrissi
Subject: RE: Loops and vectors
Based on your code, it seems like you're using two different statistical software packages, which might be causing confusion. The code you provided has a mix of syntax from different software packages, including some syntax from SPSS and some syntax that resembles R.
If you want to generate 200 random variables with a binomial distribution in SPSS, you can modify your code as follows:
VECTOR pflip(200).
LOOP #i = 1 TO 200.
COMPUTE pflip(#i) = RV.BINOM(1, 0.25).
END LOOP.
EXECUTE.
In this modified code, I've changed the vector name from pf
to pflip
to match your variable naming convention. The loop generates 200 random variables using the RV.BINOM
function, which follows the binomial distribution with a success probability of 0.25.
Please note that this code is specific to SPSS syntax. If you are using a different statistical software package, the syntax and functions may vary.
------------------------------
Youssef Sbai Idrissi
Software Engineer
------------------------------
Original Message:
Sent: Thu June 22, 2023 09:43 PM
From: Steven Andes
Subject: Loops and vectors
I need to compute 200 random variables with a binomial distribution with a success probability of .25. I will use these variables in subsequent analyses of missing data.
I called the 200 variables pflip1 to pflip200.
I started with 100 cases and four draws. I had no problem setting up the 100 cases but the two random variable draws baffle me.
Here is my code
INPUT PROGRAM.
LOOP #id=1 TO 1000.
- COMPUTE draw=UNIFORM(100).
- END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
VECTOR pf (4) .
LOOP #i = 1 to 4 .
COMPUTE pf(#i) = RV.BINOM(1,0.25).
END LOOP .
exe.
I keep getting an error message that
>Error # 4257 in column 13. Text: )
>A variable being defined on the VECTOR command already exists. To define a
>vector composed of existing variables, use the form VECTOR = VARIABLE TO
>VARIABLE.
>Execution of this command stops.
>Error # 4030 in column 9. Text: pf
>The operand appearing on the left side of the assignment operator (equals
>sign) is not a known vector name or function name.
>Execution of this command stops.
>Error # 4257 in column 13. Text: )
>A variable being defined on the VECTOR command already exists. To define a
>vector composed of existing variables, use the form VECTOR = VARIABLE TO
>VARIABLE.
>Execution of this command stops.
>Error # 4030 in column 9. Text: pf
>The operand appearing on the left side of the assignment operator (equals
>sign) is not a known vector name or function name.
>Execution of this command stops.
Please help.
------------------------------
Steven Andes
------------------------------