Hello Everyone
I have a multiple question with 28 answer options. I want to identify respondents with 3 or more than 3 "yes" answers for any of the 28 options and create a new variable. The syntax identifies the "yes" (1) but fails to increment and identify more than 3 "yes" answers for one respondent. I wrote the following syntax: COMPUTE YesCount = 0. VECTOR v1=S3Q3A.1 to S3Q3A.28. LOOP #N = 0 to 28. IF ((#n)=1) YesCount = + 1. END LOOP. EXECUTE. Please help and thanks in advance...
Roger Cupido
Technical Analyst |
You are testing the loop counter, #n, not
the variable.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: SPSS_Tech <[hidden email]> To: [hidden email] Date: 02/20/2012 07:24 AM Subject: [SPSSX-L] Increment Sent by: "SPSSX(r) Discussion" <[hidden email]> Hello Everyone I have a multiple question with 28 answer options. I want to identify respondents with 3 or more than 3 "yes" answers for any of the 28 options and create a new variable. The syntax identifies the "yes" (1) but fails to increment and identify more than 3 "yes" answers for one respondent. I wrote the following syntax: COMPUTE YesCount = 0. VECTOR v1=S3Q3A.1 to S3Q3A.28. LOOP #N = 0 to 28. IF ((#n)=1) YesCount = + 1. END LOOP. EXECUTE. Please help and thanks in advance... -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Increment-tp5499172p5499172.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Roger Cupido
something like this untested syntax should be more readable.
count YesCount = S3Q3A.1 to S3Q3A.28(1). compute ge_3_yeses + Yescount ge 3. Art Kendall Social Research Consultants On 2/20/2012 9:16 AM, SPSS_Tech wrote: > Hello Everyone > > I have a multiple question with 28 answer options. I want to identify > respondents with 3 or more than 3 "yes" answers for any of the 28 options > and create a new variable. The syntax identifies the "yes" (1) but fails to > increment and identify more than 3 "yes" answers for one respondent. > > I wrote the following syntax: > > COMPUTE YesCount = 0. > VECTOR v1=S3Q3A.1 to S3Q3A.28. > LOOP #N = 0 to 28. > IF ((#n)=1) YesCount = + 1. > END LOOP. > EXECUTE. > > Please help and thanks in advance... > > > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Increment-tp5499172p5499172.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants |
Administrator
|
In reply to this post by Roger Cupido
Keep it simple!
COUNT YesCount=S3Q3A.1 to S3Q3A.28 (1). OTOH: To answer your question: COMPUTE YesCount = 0. VECTOR v1=S3Q3A.1 to S3Q3A.28. LOOP #N = 0 to 28. + IF v1(#n) EQ 1) YesCount = YesCount+ 1. END LOOP. EXECUTE. I tend to write it as (I avoid affixing numbers to vectors and unnecessary logic): VECTOR v=S3Q3A.1 to S3Q3A.28. LOOP #N = 0 to 28. + COMPUTE YesCount=SUM(YesCount, v(#n) EQ 1). END LOOP.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Roger Cupido
As has been posted, use Count.
Just for completeness - Your SPSS code has 3 mistakes in two lines. The Loop index, as a subscript in SPSS, must be from 1, not from 0. Your variables run from ...1 to ...28, so your code (0 to 28) was not correct in any language. As has been mentioned, your IF test is done on #N and not on v1(#N). To increment YesCount, you want to set YesCount to YesCount+1, not to "+1". -- Rich Ulrich > Date: Mon, 20 Feb 2012 06:16:50 -0800 > From: [hidden email] > Subject: Increment > To: [hidden email] > > Hello Everyone > > I have a multiple question with 28 answer options. I want to identify > respondents with 3 or more than 3 "yes" answers for any of the 28 options > and create a new variable. The syntax identifies the "yes" (1) but fails to > increment and identify more than 3 "yes" answers for one respondent. > > I wrote the following syntax: > > COMPUTE YesCount = 0. > VECTOR v1=S3Q3A.1 to S3Q3A.28. > LOOP #N = 0 to 28. > IF ((#n)=1) YesCount = + 1. > END LOOP. > EXECUTE. > > Please help and thanks in advance... > > ... |
Administrator
|
Great catch on the 0 Rich ;-)
I was blind sighted by the other stuff and didn't even notice it ;-(
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Roger Cupido
Thanks to everyone for helping.
Much appreciated. Regards, Roger
Roger Cupido
Technical Analyst |
Free forum by Nabble | Edit this page |