|
I need to explain what's happening at each stage of the following
syntax. Stage 1: VECTOR X (5)/V=test1 TO test5. I presume this means to create five vectors where the initial value for each vector is equal to the values in 5 existing variables named test1 test2 test3 test4 and test5. Stage 2: LOOP #I=1 to 5. I presume this tells the syntax to create a looping index that is initially set to one but which will increment by 1 each time through the loop to a maximum of 5 iterations. Stage 3: COMPUTE X(#i)=(V(#i)=MAX(test,test2,test3,test4,test5)). I know what the Stage 3 code does, but I don't know how to explain how it does it. This stage identifies the maximum value in test1 to test5 and sets the value of the vector variable corresponding to the existing variable with the highest value equal to 1. Thus, if test1=1, test2=2, test3=6, test4=8, and test5=9, X5 is set to 1 and X1 to X4 all receive a value of 0. Could someone please explain the stage 3 code in terms of the instructions it issues to SPSS? Thanks. |
|
Hi Jim,
It looks in your Stage 3 code that you are asking SPSS to create a binary variable based on the results of a logical evaluation. So, when the variable V(#i) = MAX(test,test2,test3,test4,test5), then X(#i) receives a value of 1, or true. But when V(#i) ~= MAX(test,test2,test3,test4,test5), then X(#i) receives a value of 0, or false. The value of V(#i) will depend on the iteration within the loop. So, in the second iteration of the loop, V2 will have a value which, if equal to the maximum value existing across the five variables test through test5, will force the value for X2 to be 1. Likewise, in the *fourth* iteration of the loop, V4 will have a value which, if equal to the maximum value existing across the five variables test through test5, will force the value for X4 to be 1. However, conversely, if in the *fifth* iteration of the loop, V5 has a value which is other than the maximum value existing across the five variables test through test5, then X5 will be assigned a value of 0, or false. HTH, John Norton -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt Sent: Monday, September 10, 2007 1:46 PM To: [hidden email] Subject: Explaining vector and loop syntax I need to explain what's happening at each stage of the following syntax. Stage 1: VECTOR X (5)/V=test1 TO test5. I presume this means to create five vectors where the initial value for each vector is equal to the values in 5 existing variables named test1 test2 test3 test4 and test5. Stage 2: LOOP #I=1 to 5. I presume this tells the syntax to create a looping index that is initially set to one but which will increment by 1 each time through the loop to a maximum of 5 iterations. Stage 3: COMPUTE X(#i)=(V(#i)=MAX(test,test2,test3,test4,test5)). I know what the Stage 3 code does, but I don't know how to explain how it does it. This stage identifies the maximum value in test1 to test5 and sets the value of the vector variable corresponding to the existing variable with the highest value equal to 1. Thus, if test1=1, test2=2, test3=6, test4=8, and test5=9, X5 is set to 1 and X1 to X4 all receive a value of 0. Could someone please explain the stage 3 code in terms of the instructions it issues to SPSS? Thanks. |
|
In reply to this post by Jim Moffitt
Hi James,
In the first iteration of your loop, the COMPUTE command resolves to this: COMPUTE X1 = TEST1 = 9. What you have as an expression in creating the X1 variable is a Boolean expression. SPSS will first evaluate if TEST1 = 9. If TEST1 is equal to 9 it returns a value of 1 (for True) to the X1 variable. If not it will return a value of 0 (for False). Fast forward to the fifth iteration... The COMPUTE command resolves to: COMPUTE X5 = TEST5 = 9. Now, here TEST5 equals 9 and so a value of 1 is returned to the variable X5. Hope this helps. Florio At 02:46 PM 9/10/2007, Jim Moffitt wrote: >I need to explain what's happening at each stage of the following >syntax. > >Stage 1: VECTOR X (5)/V=test1 TO test5. >I presume this means to create five vectors where the initial value for >each vector is equal to the values in 5 existing variables named test1 >test2 test3 test4 and test5. > >Stage 2: LOOP #I=1 to 5. >I presume this tells the syntax to create a looping index that is >initially set to one but which will increment by 1 each time through the >loop to a maximum of 5 iterations. > >Stage 3: COMPUTE X(#i)=(V(#i)=MAX(test,test2,test3,test4,test5)). >I know what the Stage 3 code does, but I don't know how to explain how >it does it. >This stage identifies the maximum value in test1 to test5 and sets the >value of the vector variable corresponding to the existing variable with >the highest value equal to 1. >Thus, if test1=1, test2=2, test3=6, test4=8, and test5=9, X5 is set to >1 and X1 to X4 all receive a value of 0. > >Could someone please explain the stage 3 code in terms of the >instructions it issues to SPSS? > >Thanks. |
|
In reply to this post by Jim Moffitt
At 02:46 PM 9/10/2007, Jim Moffitt wrote:
>I need to explain what's happening at each stage of the following >syntax. > >Stage 1: VECTOR X (5)/V=test1 TO test5. >I presume this means to create five vectors where the initial value >for each vector is equal to the values in 5 existing variables named >test1 test2 test3 test4 and test5. No. It creates two vectors: . 'X', whose five elements are the five new variables 'X1', 'X2', ..., 'X5'. (The statement won't work if any of those variables existed previously.) . 'V', whose elements (I suppose there are 5) are the existing variables 'test1', 'test2', ..., 'test5'. Let me stress that last. It's not that "the initial value is equal to the values in 5 existing variables"; the 5 vector elements *are* the 5 existing variables. . COMPUTE V(3) = <expression>. is exactly equivalent to . COMPUTE test3 = <expression>. >Stage 2: LOOP #I=1 to 5. >I presume this tells the syntax to create a looping index that is >initially set to one but which will increment by 1 each time through >the loop to a maximum of 5 iterations. Yes; and the index is, of course, the scratch variable '#I'. >Stage 3: COMPUTE X(#i)=(V(#i)=MAX(test,test2,test3,test4,test5)). I gather you have a loop structure like this. (I've changed formatting for readability. And I've replaced the second '=' by 'EQ', to make clear that it's a comparison, not an assignment symbol): LOOP #I=1 to 5. . COMPUTE X(#i)= (V(#i) EQ MAX(test,test2,test3,test4,test5)). END LOOP. >This stage identifies sets [to 1] the value of the vector [element in >'V'] corresponding to the existing variable with the highest value. >Thus, if test1=1, test2=2, test3=6, test4=8, and test5=9, X5 is set >to 1 and X1 to X4 all receive a value of 0. > >Could someone please explain the stage 3 code? It's probably easier to see in the context of the LOOP. First, "MAX(test,test2,test3,test4,test5)" is, indeed, the largest value found in any of the five variables. It's a constant over the loop, so the loop could be rewritten this way, which may be clearer: COMPUTE #MaxVal = MAX(test,test2,test3,test4,test5). LOOP #I=1 to 5. . COMPUTE X(#i)= (V(#i) EQ #MaxVal)). END LOOP. Now, for example, on loop pass 2, this translates to, . COMPUTE X(2)= (V(2) EQ #MaxVal). or, since 'X(2)' is 'X2' and 'V(2)' is 'test2', . COMPUTE X2 = (test2 EQ #MaxVal). And, sure enough: it will make X2 'true' (1) or 'false' (0) depending on whether the value of test2 is the highest value found among any of the test1 to test5. Does this help? -Best of luck, Richard |
|
In reply to this post by Jim Moffitt
Step 1: Create 5 variables X1 X2 X3 X4 X5 and allow them to be
referenced as a group. Also refer to test1 test2 test3 test4 test5 as a group (with "names" V1 V2 V3 V4 V5). Step 2: Create a looping index, and pass through the cases in the dataset once for each value of the index-- in this case 5 passes. Step 3: For each pass of the looping index, compute a variable X# (where # = the indexing value of the pass) such that X# = 1 if the value of test# is the largest value of test1 test2 test3 test4 test5 for this case, and X# = 0 if the value of test# is not the largest. HTH --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt Sent: Monday, September 10, 2007 1:46 PM To: [hidden email] Subject: Explaining vector and loop syntax I need to explain what's happening at each stage of the following syntax. Stage 1: VECTOR X (5)/V=test1 TO test5. I presume this means to create five vectors where the initial value for each vector is equal to the values in 5 existing variables named test1 test2 test3 test4 and test5. Stage 2: LOOP #I=1 to 5. I presume this tells the syntax to create a looping index that is initially set to one but which will increment by 1 each time through the loop to a maximum of 5 iterations. Stage 3: COMPUTE X(#i)=(V(#i)=MAX(test,test2,test3,test4,test5)). I know what the Stage 3 code does, but I don't know how to explain how it does it. This stage identifies the maximum value in test1 to test5 and sets the value of the vector variable corresponding to the existing variable with the highest value equal to 1. Thus, if test1=1, test2=2, test3=6, test4=8, and test5=9, X5 is set to 1 and X1 to X4 all receive a value of 0. Could someone please explain the stage 3 code in terms of the instructions it issues to SPSS? Thanks. |
|
Thanks, Jim (and Richard Ristow, Florio Arguillas and John Norton). All
of your explanations were most helpful. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marks, Jim Sent: Monday, September 10, 2007 2:57 PM To: [hidden email] Subject: Re: Explaining vector and loop syntax Step 1: Create 5 variables X1 X2 X3 X4 X5 and allow them to be referenced as a group. Also refer to test1 test2 test3 test4 test5 as a group (with "names" V1 V2 V3 V4 V5). Step 2: Create a looping index, and pass through the cases in the dataset once for each value of the index-- in this case 5 passes. Step 3: For each pass of the looping index, compute a variable X# (where # = the indexing value of the pass) such that X# = 1 if the value of test# is the largest value of test1 test2 test3 test4 test5 for this case, and X# = 0 if the value of test# is not the largest. HTH --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim Moffitt Sent: Monday, September 10, 2007 1:46 PM To: [hidden email] Subject: Explaining vector and loop syntax I need to explain what's happening at each stage of the following syntax. Stage 1: VECTOR X (5)/V=test1 TO test5. I presume this means to create five vectors where the initial value for each vector is equal to the values in 5 existing variables named test1 test2 test3 test4 and test5. Stage 2: LOOP #I=1 to 5. I presume this tells the syntax to create a looping index that is initially set to one but which will increment by 1 each time through the loop to a maximum of 5 iterations. Stage 3: COMPUTE X(#i)=(V(#i)=MAX(test,test2,test3,test4,test5)). I know what the Stage 3 code does, but I don't know how to explain how it does it. This stage identifies the maximum value in test1 to test5 and sets the value of the vector variable corresponding to the existing variable with the highest value equal to 1. Thus, if test1=1, test2=2, test3=6, test4=8, and test5=9, X5 is set to 1 and X1 to X4 all receive a value of 0. Could someone please explain the stage 3 code in terms of the instructions it issues to SPSS? Thanks. |
| Free forum by Nabble | Edit this page |
