Hello people at SPSSX-L,
Would you help me figure out how to write some SPSS syntax that creates a variable Z out of values for ID and X? One way to look at the rule is: * If there' s only one row for that ID, Z="yes" (see IDs 1 & 2) * Else, ** if there's just one row where X=1, that row's Z="yes", other rows' Z= "No" (see ID 3) ** else all rows' s Z = "Check" (see IDs 4 and 5). N ID X Z 1 1 0 Yes 2 2 1 Yes 3 3 0 No 4 3 1 Yes 5 3 0 No 6 4 1 Check 7 4 1 Check 8 5 0 Check 9 5 0 Check 10 5 1 Check 11 5 1 Check (if it was in a different language I would create a list for each ID/X cell, populated by the concatenated values of N, and go from there). ===================== 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 |
Administrator
|
Take a look at the AGGREGATE command (see MODE=ADDVARIABLES and SUM
function). Untested: AGGREGATE OUTFILE * /MODE ADDVARIABLES / Sum_Z=SUM(Z). roll on from there! Zuluaga, Juan wrote > > Hello people at SPSSX-L, > Would you help me figure out how to write some SPSS syntax that creates a > variable Z out of values for ID and X? > One way to look at the rule is: > * If there' s only one row for that ID, Z="yes" (see IDs 1 & 2) > * Else, > ** if there's just one row where X=1, that row's Z="yes", other rows' Z= > "No" (see ID 3) > ** else all rows' s Z = "Check" (see IDs 4 and 5). > > N ID X Z > 1 1 0 Yes > 2 2 1 Yes > 3 3 0 No > 4 3 1 Yes > 5 3 0 No > 6 4 1 Check > 7 4 1 Check > 8 5 0 Check > 9 5 0 Check > 10 5 1 Check > 11 5 1 Check > > (if it was in a different language I would create a list for each ID/X > cell, populated by the concatenated values of N, and go from there). > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA (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 > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/to-flag-some-rows-of-a-longitudinal-file-tp5202691p5232975.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
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?" |
Administrator
|
In reply to this post by Zuluaga, Juan
Take a look at the AGGREGATE command (see MODE=ADDVARIABLES and SUM function).
Untested: AGGREGATE OUTFILE * /MODE ADDVARIABLES / Sum_X=SUM(X). roll on from there!
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 Zuluaga, Juan
Juan,
I think this will will work although i have not tested it. Gene Maguin compute z='Check'. aggregate outfile=* mode=addvariables/break=id/nid=nu/sumx=sum(x). if (nid eq 1) z='yes'. if (nid gt 1) z='no'. if (nid gt 1 and sumx eq 1 and x eq 1) z='yes'. On Mon 01/23/12 7:22 PM , "Zuluaga, Juan" [hidden email] sent: > Hello people at SPSSX-L, > Would you help me figure out how to write some SPSS syntax that creates a > variable Z out of values for ID and X?One way to look at the rule is: > * If there' s only one row for that ID, Z="yes" (see IDs 1 & > 2)* Else, > ** if there's just one row where X=1, that row's Z="yes", other > rows' Z= "No" (see ID 3)** else all rows' s Z = "Check" (see IDs 4 and 5). > > N ID X Z > 1 1 0 Yes > 2 2 1 Yes > 3 3 0 No > 4 3 1 Yes > 5 3 0 No > 6 4 1 Check > 7 4 1 Check > 8 5 0 Check > 9 5 0 Check > 10 5 1 Check > 11 5 1 Check > > (if it was in a different language I would create a list for each ID/X > cell, populated by the concatenated values of N, and go from there). > ===================== > To manage your subscription to SPSSX-L, send a message to > LIS > [hidden email] (not to SPSSX-L), with no body text except > thecommand. 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 |
In reply to this post by Zuluaga, Juan
David, Gene, thank you a million for introducing me to the Aggregate command.
The script I rewrote as aggregate outfile=* mode=addvariables /break=Id /nid=nu /sumx=sum(x). if (nid eq 1) z='yes'. if (nid gt 1 and sumx eq 1 and x eq 1) z='yes'. if (nid gt 1 and sumx eq 1 and x eq 0) z='no'. if (nid gt 1 and sumx NE 1) z="Check". execute. ===================== 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 |
Free forum by Nabble | Edit this page |