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 (April 2007)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 11 Apr 2007 16:38:27 -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: calculating duration of status
Comments: To: J Scelza <jfs37@GEORGETOWN.EDU>
In-Reply-To:  <200704101745.l3AFRV4m002899@mailgw.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"; format=flowed

(This is a follow-up to thread "syntax for creating a pattern variable", Fri, 16 Mar 2007 <12:17:02 -0400> ff.)

At 01:45 PM 4/10/2007, J Scelza wrote:

>I have a data set which contains the following: >1) at least two records per client; >2) one time variable called "date of employment"; and >3) three variables indicating employment status of a client: > "employment status" (1=employed, 3=unemployed), > "employment change 1" (2=changed from employed to unemployed, > -2=changed from unemployed to employed, > 0=no change from the previous record > for this client), > and "employment change 2" (1=employed to unemployed, > 2=unemployed to employed, > 3=oscillating employment, and > 4=no overall subsequent change > in employment). > > >I would like to determine the length of time that a client was >employed or unemployed before his or her status changed. At the very >least, where a client has a continuous employment status (like CaseID >7 in the example above), I would like to determine how long (in days) >he or she was employed.

It's not clear what you want: whether one number for each continuous period in the same status, one number per client, or what? And as you have it, you can't get duration in days. Your date resolution is to month, only; you don't have the dates of status change.

Anyway, try the below as a beginning. I'm taking the problem, and the logic, as very similar to thread "Counting Consecutive Dates or Gaps in dates" (dates, Wed, 4 Apr 2007 <10:17:44 -0400> ff; my solution, Wed, 4 Apr 2007 <14:10:00 -0400>). SPSS 15 draft output:

|-----------------------------|---------------------------| |Output Created |11-APR-2007 16:33:34 | |-----------------------------|---------------------------| CaseID StatusDT EmpStatus EmpChange1 EmpChange2

1 01-APR-2006 1 . 4 1 01-MAY-2006 1 0 4 3 01-AUG-2005 3 . 3 3 01-SEP-2005 1 -2 3 3 01-OCT-2005 3 2 3 4 01-AUG-2005 3 . 2 4 01-SEP-2005 1 -2 2 5 01-FEB-2006 1 . 1 5 01-MAR-2006 3 2 1 6 01-MAR-2006 1 . 3 6 01-APR-2006 3 2 3 6 01-MAY-2006 1 -2 3 7 01-JAN-2006 1 . 4 7 01-FEB-2006 1 0 4 7 01-MAR-2006 1 0 4 7 01-APR-2006 1 0 4 7 01-MAY-2006 1 0 4

Number of cases read: 17 Number of cases listed: 17

* "I would like to determine the length of time that a client . * was employed or unemployed before his or her status changed".

* Step I: Length of time, through current month . * (Logic assumes that CaseID and EmpStatus are never missing) .

NUMERIC TimeInStat (F3). VAR LABEL TimeInStat 'Number of months in current employment status'. DO IF MISSING(LAG(CaseID)). . COMPUTE TimeInStat = 1. ELSE IF CaseID NE LAG(CaseID). . COMPUTE TimeInStat = 1. ELSE IF EmpStatus NE LAG(EmpStatus). . COMPUTE TimeInStat = 1. ELSE. . COMPUTE TimeInStat = 1 + LAG(TimeInStat). END IF. LIST.

List |-----------------------------|---------------------------| |Output Created |11-APR-2007 16:33:35 | |-----------------------------|---------------------------| CaseID StatusDT EmpStatus EmpChange1 EmpChange2 TimeInStat

1 01-APR-2006 1 . 4 1 1 01-MAY-2006 1 0 4 2 3 01-AUG-2005 3 . 3 1 3 01-SEP-2005 1 -2 3 1 3 01-OCT-2005 3 2 3 1 4 01-AUG-2005 3 . 2 1 4 01-SEP-2005 1 -2 2 1 5 01-FEB-2006 1 . 1 1 5 01-MAR-2006 3 2 1 1 6 01-MAR-2006 1 . 3 1 6 01-APR-2006 3 2 3 1 6 01-MAY-2006 1 -2 3 1 7 01-JAN-2006 1 . 4 1 7 01-FEB-2006 1 0 4 2 7 01-MAR-2006 1 0 4 3 7 01-APR-2006 1 0 4 4 7 01-MAY-2006 1 0 4 5

Number of cases read: 17 Number of cases listed: 17

* Step II: Length of interval of one employment status .

NUMERIC StatStrtDT (DATE11). VAR LABEL StatStrtDT 'Date when current status began'. DO IF TimeInStat EQ 1. . COMPUTE StatStrtDT = StatusDT. ELSE. . COMPUTE StatStrtDT = LAG(StatStrtDT). END IF.

AGGREGATE OUTFILE=* /BREAK = CaseID StatStrtDT /EmpStatus = FIRST(EmpStatus) /StatusLN 'Duration in status, months' = MAX(TimeInStat).

LIST.

List |-----------------------------|---------------------------| |Output Created |11-APR-2007 16:33:36 | |-----------------------------|---------------------------| CaseID StatStrtDT EmpStatus StatusLN

1 01-APR-2006 1 2 3 01-AUG-2005 3 1 3 01-SEP-2005 1 1 3 01-OCT-2005 3 1 4 01-AUG-2005 3 1 4 01-SEP-2005 1 1 5 01-FEB-2006 1 1 5 01-MAR-2006 3 1 6 01-MAR-2006 1 1 6 01-APR-2006 3 1 6 01-MAY-2006 1 1 7 01-JAN-2006 1 5

Number of cases read: 12 Number of cases listed: 12 =================== APPENDIX: Test data =================== * ............ Test data ............ . * (from the original posting) .

DATA LIST LIST SKIP=1/ CaseID StatusDT EmpStatus EmpChange1 EmpChange2 (F2, DATE, 3F2). BEGIN DATA CaseID Date of Emp Status EmpStatus EmpChange1 EmpChange2 1 01-APR-2006 1 . 4 1 01-MAY-2006 1 0 4 3 01-AUG-2005 3 . 3 3 01-SEP-2005 1 -2 3 3 01-OCT-2005 3 2 3 4 01-AUG-2005 3 . 2 4 01-SEP-2005 1 -2 2 5 01-FEB-2006 1 . 1 5 01-MAR-2006 3 2 1 6 01-MAR-2006 1 . 3 6 01-APR-2006 3 2 3 6 01-MAY-2006 1 -2 3 7 01-JAN-2006 1 . 4 7 01-FEB-2006 1 0 4 7 01-MAR-2006 1 0 4 7 01-APR-2006 1 0 4 7 01-MAY-2006 1 0 4 END DATA. SORT CASES BY CaseID StatusDT.


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