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 (May 2004)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 10 May 2004 13:17:32 -0500
Reply-To:     "Marks, Jim" <Jim.Marks@lodgenet.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         "Marks, Jim" <Jim.Marks@lodgenet.com>
Subject:      Re: selecting cases
Content-Type: text/plain; charset="us-ascii"

Jed:

In order to use LAG, you need the case with the event before the case you want to flag in the data file-- i.e. you need to sort in descending order of time/ interval.

The basic logic is:

1) sort by interval (and any other relevant grouping variables).

2) optional: create a "sortord" variable (I think it improves processing time if there are less variables to sort on).

3) flag your cases of interest.

4) sort by Descending order of the sortord variable.

5) use LAG to the "previous" case with the event of interest.

6) resort to restore original order.

Here is sample syntax:

** sample data. DATA LIST FREE /grp (F8.0) event (F8.0) date (ADATE10) time (TIME10). BEGIN DATA 1 1 10/01/2001 09:18:03 1 2 10/01/2001 19:11:11 1 9 10/01/2001 15:15:15 2 2 10/01/2001 07:18:03 2 1 10/01/2001 19:11:11 2 9 10/11/2001 15:15:15 END DATA.

** sort and create sortord variable. SORT CASES BY grp date time. COMPUTE sortord EQ $CASENUM.

** flag cases of interest-- event = 9. COMPUTE flgevent EQ event EQ 9.

** descending intervals. SORT CASES by sortord (D).

** flag prior event. COMPUTE prvevent EQ grp EQ LAG(GRP) and LAG(event) eq 9. RECODE prvevent (SYSMIS = 0).

** restore original order. SORT CASES by sortord.

You can filter or select on the event of interest, and the prior event using the variables flgevent and prevent.

cheers

--jim

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Jed J. Teres Sent: Monday, May 10, 2004 12:42 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: selecting cases

Hello all.

I have an observation-level data set and I need to select observations in which a certain event occurs as well as the preceding interval.

Selecting the event intervals is easy- I can just say, "select if (event eq 1)." How can I get the case immediately preceding this one?

Thanks,

Jed Teres


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