Could Lags solve this sequencing problem

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Could Lags solve this sequencing problem

Snuffy Dog

Dear Listers,

 

I am writing for some assistance in creating a field called Episode. I have created an input data file to assist with this process. 
 
DATA LIST / Espisode (F2.0) Patient_id (F1.0) Context (A1) Occasion_type (A1) Occasion_date (edate10).
BEGIN DATA
031OR1/05/2000
031OA1/02/2000
011OD1/04/1999
011OR 2/03/1999
011OR20/03/1999
051OR15/03/2001
061IA19/03/2003
071IA22/03/2003
071ID26/03/2003
021IR2/04/1999
041IR21/12/2000
041ID25/12/2000
242IA28/09/2000
232OA1/06/2000
242ID25/12/2000
END DATA.
COMPUTE ID = $casenum.
STRING Context_1 (A10) Occasion_type_1 (A10).
IF context = 'I' context_1 = 'Inpatient'.
IF context = 'O' context_1 = 'Outpatient'.
IF Occasion_type = 'A' Occasion_type_1 = 'Admission'.
IF Occasion_type = 'R' Occasion_type_1 = 'Review'.
IF Occasion_type = 'D' Occasion_type_1 = 'Discharge'.
EXECUTE.
DELETE VARIABLES context occasion_type.
EXECUTE.
SORT CASES BY Espisode(A) Occasion_date(A).
 
I am trying to find the best code to create the field, 'Episode'. I have put the values I am wanting to create within in the 'Episode' column - these values for Episode are the solution I am looking for.

 

I have Inpatients and Outpatients who receive assessments at different stages of their care, these are Admissions, Reviews and Discharges. 

 

An Episode of Care is defined as an Admission, a Review, sometimes further Reviews and then a Discharge.  There can be Inpatient Episodes and Outpatient Episodes for the same patient. 
 
The example data I have provides contains Admission, Reviews and Discharges for 2 patients, patient 1 and patient 2.

 

I am wanting to create a variable, 'Episode' for each episode of care.  Unfortunately sometimes admissions, reviews and discharges are missing from the dataset - so this complicates the process. 

 

There are several rules that must be observed.  If a patient moves form being an Outpatient to being an Inpatient then this is a new Episode of care.  If a patient moves from being an Inpatient to being an Outpatient then this again is a new Episode of care.  Take as an example, if an outpatient Admission is immediately followed in time by an Inpatient Review then this tells us that the patient has been discharged from an outpatient setting and then admitted as an Inpatient.  Therefore the outpatient Admission should have an Episode ID that is different from the Episode ID we have for the Inpatient review. The Episode field must be unique to episode and the patient. We cannot have 2 different patients within the same Episode ID.

 

I was thinking that some kind of lag function is probably the solution. 

 

I would greatly appreciate any assistance that the good people of this listserve can provide.
 
Kind regards,
 
Jonathon
Reply | Threaded
Open this post in threaded view
|

Re: Could Lags solve this sequencing problem

Andy W
Yes I would approach this using lagged values. Below is an example what I think you want in the end given the description of the data. Comments should be clear how the code is defining a transition between episodes.

This can likely be cleaned up some, for instance if you split the file by patient id you shouldn't need to do all the "Patient_id = lag(Patient_id)" in many of the definitions (see related discussions in the comments here by David Marso). Hopefully this is a good start though!

Thank you for the example dataset and clear question!

*****************************************************.
DATA LIST / Espisode (F2.0) Patient_id (F1.0) Context (A1) Occasion_type (A1) Occasion_date (edate10).
BEGIN DATA
031OR1/05/2000
031OA1/02/2000
011OD1/04/1999
011OR 2/03/1999
011OR20/03/1999
051OR15/03/2001
061IA19/03/2003
071IA22/03/2003
071ID26/03/2003
021IR2/04/1999
041IR21/12/2000
041ID25/12/2000
242IA28/09/2000
232OA1/06/2000
242ID25/12/2000
END DATA.

*First sort by Patient ID, and then Occasion Date, and then context (recoded into numeric).
*I sort by occasion in the case that two contexts happen on same day.
recode Occasion_type ('A' = 1)('R' = 2)('D' = 3) into OTn.
sort cases by Patient_id Occasion_date OTn.

*Definitions for a "new episode" - contained within new_epi category.
compute new_epi = 0.
*First time a patient is in dataset - or very first record in dataset.
if Patient_id <> lag(Patient_id) new_epi = 1.
if $casenum = 1 new_epi = 1.
*Move from inpatient to outpatient or vice-versa.
if Patient_id = lag(Patient_id) and Context <> lag(Context) new_epi = 1.
*If prior is a discharge, follow up is a new episode.
if Patient_id = lag(Patient_id) and lag(Occasion_type) = 'D' new_epi = 1.
*if current is admission and prior is either review or admission- current is a new episode.
if Patient_id = lag(Patient_id) and Occasion_type = 'A' and lag(Occasion_type) = 'A' new_epi = 1.
if Patient_id = lag(Patient_id) and Occasion_type = 'A' and lag(Occasion_type) = 'R' new_epi = 1.
*note - if you have both missing admission and discharge, you wont be able to tell if it is a new episode.
*You can see now that I have a value of 1 in the new_epi category wherever
you have a transition between your manually created "Espisode" variable.

*Now make a counter for a new episode.
if Patient_id <> lag(Patient_id) EpiCounter = 1.
if $casenum = 1 EpiCounter = 1.
do if Patient_id = lag(Patient_id) and new_epi = 0.
    compute EpiCounter = lag(EpiCounter).
else if Patient_id = lag(Patient_id) and new_epi = 1.
    compute EpiCounter = lag(EpiCounter) + 1.
end if.
exe.
*****************************************************.

Actually the request to make a unique id per patient and episode takes a bit more context. If this is a static dataset and you only need to do it once, you can do it however you want. For example, if you took out the "Patient_id = lag(Patient_id)" condition in the last set of statements, it would produce a counter for every episode patient id pair in the dataset.

*****************************************************.
if $casenum = 1 EpiCounter2 = 1.
do if new_epi = 0.
    compute EpiCounter2 = lag(EpiCounter2).
else if new_epi = 1 and $casenum > 1.
    compute EpiCounter2 = lag(EpiCounter2) + 1.
end if.
exe.
*****************************************************.

If you need to update this on a regular basis though, this is not how I would suggest you do this. You would basically need to add in the new data to your old data, and then calculate this for the new values. If you knew an absolute value for the size of potential new episodes and potential new patients (or at least knew a value it would never surpass), you could make a string variable that is the concatenation of the patient id and episode.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/