Date: Tue, 1 Oct 2002 14:46:01 -0400
Reply-To: Richard Ristow <email@example.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Richard Ristow <firstname.lastname@example.org>
Subject: Re: Series within conditions
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.
>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
>SORT CASES BY sess valence reltime.
>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.
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
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.