Continuous/Discrete Dates

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Lizzie
Posts: 4
Joined: Thu Jun 07, 2012 1:24 pm

Continuous/Discrete Dates

Postby Lizzie » Wed Feb 27, 2013 8:07 pm

Hey there,

I am trying to look at a set of data with a date field (ServiceDate). To identify an episode, the same services occur within 10 days are treated as an episode (such as ID#1 S0001 on 1/9/2011 and 1/16/2011). With this long format, How can I write a syntax to identify episodes? My data look like as follows.

ID Service ServiceDate
1 S0001 1/9/2011
1 S0001 1/16/2011
1 S0002 9/9/2011
2 S0003 8/22/2011
3 S0001 3/9/2011
3 S0001 3/28/2011
3 S0001 4/9/2011
3 S0003 6/9/2011
3 S0004 7/23/2011
4 S0002 10/9/2010
4 S0001 5/21/2011

Thanks a lot.
mirirai
Posts: 6
Joined: Thu Feb 07, 2013 9:46 am

Re: Continuous/Discrete Dates

Postby mirirai » Thu Feb 28, 2013 10:50 am

Hi Lizzie,

Do I understand this right, that if some cases have the same id and Servicenumber the episode variable should be set to 1 (yes-bit)?

you can do this using the LAG command (works only if the cases are ordered by "id" and "service"):

Code: Select all

COMPUTE episode=1.
IF (id=LAG(id) AND service=LAG(service)) episode=1.

* Now every case which is part of an episode is set to 1, except from the first case of each episode.
* So we have to reorder and repeat the IF command.
SORT CASES id (A) service (A) servicedate (D).
IF (id=LAG(id) AND service=LAG(service)) episode=1.
EXECUTE.
PS: I didn't take account for the differences between the dates, because I assume that this is already reflected by the service variable.

Who is online

Users browsing this forum: No registered users and 2 guests

cron