LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2002)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 1 Oct 2002 14:46:01 -0400
Reply-To:     Richard Ristow <wrristow@mindspring.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Richard Ristow <wrristow@mindspring.com>
Subject:      Re: Series within conditions
Comments: To: "Heather L. Urry" <hlurry@facstaff.wisc.edu>
In-Reply-To:  <JAEFJAPAEBFCDIHJIFKCOEKOCGAA.rlevesque@videotron.ca>
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 09:37 PM 9/27/2002 -0400, Raynald Levesque wrote, responding to Heather Urry's question of Fri, 27 Sep 2002 20:14:21 -0500, i.e.

>I'd like to number cases consecutively within conditions. The >conditions are defined by three variables (session, valence, and >reltime). I suspect I need to use the loop command [...]

Raymond Levesque's response is, of course, accurate:

>DATA LIST LIST /id sess valence reltime. >BEGIN DATA >1 1 1 1 >2 1 1 1 >3 1 1 1 >4 1 2 4 >5 1 2 4 >6 2 2 2 >7 2 2 2 >7 2 2 2 >END DATA. >LIST. > >SORT CASES BY sess valence reltime. >COMPUTE casen=$CASENUM. >RANK VARIABLES=casen BY reltime sess valence /RANK INTO nb .

It may be more direct to COMPUTE directly rather than using RANK. With data as given, you'd do this:

SORT cases by sess valence reltime. /* As before */ /* See "Remarks":" */ MATCH FILES FILE=* /BY sess valence reltime /* Note 1. */ /FIRST = NEW_COND .

NUMERIC nb (F3). /* "nb" is the new case number within conditions*/ LEAVE nb. /* Note 2. */

IF (NEW_COND = 1) nb = 0. /* Note 3. */ COMPUTE nb = nb + 1. EXECUTE.

Remarks: ------- 1. "MATCH FILES/FILE=*" is not documented, but it works and is very useful for this and some other effects. The point is to identify the start of a new 'condition' (as defined by sess, valence, and reltime); you could also use LAG on those three variables, but you'd have to test all three, so the code is clumsier. Note that you're not actually combining files.

2. "LEAVE" keeps the value of variable "nb" intact from case to case, so you can increment it without using the LAG function.

3. In this logic, "NEW_COND" marks the start of a new 'condition'. Since nb is incremented for every case, resetting to nb=0 means the first case of each 'condition' will be numbered 1.


Back to: Top of message | Previous page | Main SPSSX-L page