Hi
I want to create a variable for sampling purposes. The variable should number all the cases from 1 to 10, i.e. once it reaches 10 for a set of cases it needs to start at 1 again. Case New_var 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 1 12 2 13 3 14 4 15 5 16 6 17 7 18 8 19 9 20 10 21 1 22 2 23 3 24 4 25 5 26 6 27 7 28 8 29 9 30 10 Is this possible? Thanks, Roger
Roger Cupido
Technical Analyst |
Bit crude, but it works.
compute newvar = $casenum . if (newvar > 10) newvar = $casenum - trunc ( v1/10) * 10 . if (newvar = 0) newvar =10 . format newvar (f2.0) . exec . John F Hall [hidden email] www.surveyresearch.weebly.com -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of SPSS_Tech Sent: 01 September 2011 09:27 To: [hidden email] Subject: Compute New Variable Hi I want to create a variable for sampling purposes. The variable should number all the cases from 1 to 10, i.e. once it reaches 10 for a set of cases it needs to start at 1 again. Case New_var 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 1 12 2 13 3 14 4 15 5 16 6 17 7 18 8 19 9 20 10 21 1 22 2 23 3 24 4 25 5 26 6 27 7 28 8 29 9 30 10 Is this possible? Thanks, Roger -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Compute-New-Variable-tp4757373 p4757373.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 |
Administrator
|
I can't test this right now--my v18 license just expired, and the university hasn't provided us with the v19 license yet. But I think MOD will work very nicely here.
compute newvar = mod($casenum,10). if newvar EQ 0 newvar = 10. HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
You can shorten this to one statement in a natural way,
compute newvar = mod($casenum,10) + 1. -- Rich Ulrich > Date: Thu, 1 Sep 2011 05:24:17 -0700 > From: [hidden email] > Subject: Re: Compute New Variable > To: [hidden email] > > I can't test this right now--my v18 license just expired, and the university > hasn't provided us with the v19 license yet. But I think MOD will work very > nicely here. > > compute newvar = mod($casenum,10). > if newvar EQ 0 newvar = 10. > |
Administrator
|
And if you want to just be silly try :
COMPUTE #=SUM(SUM(#,1)*(#<10),(#>9)). COMPUTE NewVar=#. ;-)))
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?" |
Thanks guys everyone's suggestions really helped. Roger On Fri, Sep 2, 2011 at 1:36 AM, David Marso [via SPSSX Discussion] <[hidden email]> wrote: And if you want to just be silly try : -- Regards,
Roger Cupido
BBM: 212CEF76
Cell: 072 971 0410
Skype: roge-roge
Roger Cupido
Technical Analyst |
Free forum by Nabble | Edit this page |