|
I need to select cases from a specific date/program forward in time. Listed below is the data layout.
caseid, year,program 1 2001 A 1 2003 A 1 2004 B 1 2005 B 2 2003 A 2 2004 B 2 2005 A 3 2001 B I would need to sel cases when the subjects "started" program B & any following years. Notice in case #2 I would need the last 2 records. I though prehaps a lag fucntion here to denote when program B starts might work but confused in case #2. Thanks in advance, David ===================== 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 |
|
At 11:37 AM 10/28/2007, David Wright wrote:
>I need to select cases from a specific date/program forward in >time. Listed below is the data layout. [As SPSS 14 LIST output; >modified, adding variable RecdNum.] |-----------------------------|---------------------------| |Output Created |28-OCT-2007 13:55:38 | |-----------------------------|---------------------------| [TestData] RcrdNum caseid year program 001 1 2001 A 002 1 2003 A 003 1 2004 B 004 1 2005 B 005 2 2003 A 006 2 2004 B 007 2 2005 A 008 3 2001 B Number of cases read: 8 Number of cases listed: 8 >I would need to select cases when the subjects "started" program B & >any following years. Notice in case #2 I would need the last 2 >records. > >I thought perhaps a lag fucntion here to denote when program B starts >might work but confused in case #2. Selecting cases using LAG is notoriously tricky, but this instance seems straightforward. I believe the following gives what you want. It's SPSS 14 draft output (WRR:not saved separately). The dataset's called "NaiveLag", because I was afraid I'd have trouble and have to code a more elaborate alternative. DATASET ACTIVATE NaiveLag. SELECT IF program EQ 'B' OR caseid EQ LAG(caseid). LIST. List |-----------------------------|---------------------------| |Output Created |28-OCT-2007 14:09:08 | |-----------------------------|---------------------------| [NaiveLag] RcrdNum caseid year program 003 1 2004 B 004 1 2005 B 006 2 2004 B 007 2 2005 A 008 3 2001 B Number of cases read: 5 Number of cases listed: 5 =================== APPENDIX: Test data =================== * ................................................................. . * ................. Test data ..................... . INPUT PROGRAM. . NUMERIC RcrdNum (N3). . LEAVE RcrdNum. . COMPUTE RcrdNum = RcrdNum + 1. . DATA LIST FREE / caseid year program (F2, F4, A2). END INPUT PROGRAM. BEGIN DATA 1 2001 A 1 2003 A 1 2004 B 1 2005 B 2 2003 A 2 2004 B 2 2005 A 3 2001 B END DATA. DATASET NAME TestData. LIST. DATASET COPY NaiveLag. DATASET COPY Execute. DATASET COPY Involved. ===================== 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 |
