Hi STATA users, I have a longitudinal dataset with which I am trying to generate a 'length of service' variable that represents the time period of engagement of an individual with a community health service, after discharge from hospital. I have the following variables:
- 'ppn' = identifier
- presentMH_nonfmt = date seen by service
- start_nonfmtd = date presenting to hospital
- sepdate_non_fmtd = date separated from hospital
- I have generated 'AMBMH_7days_after = 1 if presentMH_nonfmt > sepdate_non_fmt & presentMH_nonfmt < sepdate_nn_fmtd +8 (** This is a service indicator stating whether the person attending the community service within the week after d/c from hospital)
- activity_code1 = string categorical vble which describes service activity - may or may not start with 'open request' but I want to calculate LENGTH OF SERVICE for first day of engagement after hospital (if <8 days) until activity_code1 variable states 'Close Request'.
NB: The 'start' and 'sepdate' values were merged in from an incident hospital admission dataset - by ppn - so the date of that incident start and sepdate seen is therefore the same for all.
*** Example data generated by dataex: ssc install dataex
clear
*** I hope this makes sense?
Thank you in advance from any advice.
Lisa
- 'ppn' = identifier
- presentMH_nonfmt = date seen by service
- start_nonfmtd = date presenting to hospital
- sepdate_non_fmtd = date separated from hospital
- I have generated 'AMBMH_7days_after = 1 if presentMH_nonfmt > sepdate_non_fmt & presentMH_nonfmt < sepdate_nn_fmtd +8 (** This is a service indicator stating whether the person attending the community service within the week after d/c from hospital)
- activity_code1 = string categorical vble which describes service activity - may or may not start with 'open request' but I want to calculate LENGTH OF SERVICE for first day of engagement after hospital (if <8 days) until activity_code1 variable states 'Close Request'.
NB: The 'start' and 'sepdate' values were merged in from an incident hospital admission dataset - by ppn - so the date of that incident start and sepdate seen is therefore the same for all.
*** Example data generated by dataex: ssc install dataex
clear
Code:
input long ppn float presentMH_nonfmt float start_nonfmtd float sepdate_nonfmtd float AMBMH_7days_after str11 activity_code1 0071 21808 21807 21808 . "triage" 0071 21809 21807 21808 1 "counselling" 0071 21812 21807 21808 1 "Assess" 0071 21817 21807 21808 . "CareMx" 0071 21832 21807 21808 . "CareConf" 0071 21836 21807 21808 . "CareMx" 0071 21840 21807 21808 . "Counselling" 0071 21843 21807 21808 . "CareMx" 0071 21843 21807 21808 . "CloseReq" 00132 21182 21180 21181 1 "CarePlan" 00132 21182 21180 21181 1 "CarePlan" 00132 21183 21180 21181 1 "CarePlan" 00132 21184 21180 21181 1 "Assess" 00132 21186 21180 21181 1 "CareMx" 00132 21186 21180 21181 1 "CloseReq" end format presentMH_nonfmt start_nonfmtd sepdate_nonfmtd %td
Thank you in advance from any advice.

Lisa
Comment