|
can someone plz help me with this:
two of the variables i have in my data set are ID and Age. So, for each ID, I have a different row of data for each month. but the age variables aren't always the same. ie one ID could go Age = 28, 58, 88, etc. another ID could go Age = 29, 59, 89,...etc. i want to be able to split the file by monthly age so I can run some statistical analyses per month. is there any way i can create a new counter variable that for each ID, goes in increasing order of age. and then the counter resets once i hit another ID. That way any value of 1 in my new variable would stand for data in the first month of an ID, any 2 would stand for data in the second month of an ID, etc. any ideas? thanks! |
|
At 04:42 PM 2/26/2009, jimjohn wrote:
two of the variables i have in my data set are ID and Age. For each ID, Creating a counter variable within groups defined by an ID variable is something of a FAQ: FAQ: Sequence numbers & random sequence numbers for cases This is only relevant for sequencing within groups of cases. For sequencing the whole file, COMPUTE SeqnNumb = $CASENUM. is much the easiest. ........................ To create sequence numbers within groups (letters refer to the citations at the end of this posting): Using a transformation program(a): DO IF $CASENUM EQ 1 OR Group NE LAG(Group). . COMPUTE SeqnNumb = 1. ELSE. . COMPUTE SeqnNumb = LAG(SeqnNumb) + 1. END IF. Using CREATE(b): COMPUTE NOBREAK = 1. FORMATS NOBREAK (F2). SPLIT FILE BY Group. CREATE SeqnNumb = CSUM(NOBREAK). Using RANK(c): COMPUTE id=$casenum. RANK VARIABLES=ID(A) BY Group /RANK INTO SeqnNumb /PRINT=NO . DELETE VARIABLES id. FORMAT SeqnNumb (F4). Random sequencing within groups(d): COMPUTE RandKey = RV.UNIFORM(0,1). RANK RandKey (A) BY GROUP /RANK INTO RandSeqn. .................................... (a) This method is around. I've written the code for this FAQ, rather than looking for a citation. (b) Date: Tue, 13 Nov 2007 22:46:32 -0500 From: Richard Ristow <[hidden email]> Subject: Re: Consecutive numbers of different size To: [hidden email] (c)Date: Wed, 14 Nov 2007 07:42:06 +0100 From: Marta GarcĂa-Granero <[hidden email]> Subject: Re: Consecutive numbers of different size To: [hidden email] (d)Date: Tue, 15 Jan 2008 11:15:44 -0800 From: King Douglas <[hidden email]> Subject: Re: drawing samples for hundreds of workers To: [hidden email] ====================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 |
