I have a dataset of assessments with identifiers for the patient and the admission and discharge dates identifying the separate stays. My data contain the first 4 columns in the table below. I am trying to create the fifth variable ("stay") which is an identifier of each stay within individual patient and groups assessments completed within a given stay.
The following code (Stata 15) gets me close, but does not start the "stay" value at '1' for each new ID.
sort ID admit discharge
egen stay = group(ID admit discharge)
The last column (stay_desired) shows the desired outcome.
Thanks for any guidance!
Regards,
Jenefer
The following code (Stata 15) gets me close, but does not start the "stay" value at '1' for each new ID.
sort ID admit discharge
egen stay = group(ID admit discharge)
The last column (stay_desired) shows the desired outcome.
ID | admit | discharge | assessment | stay | stay_desired |
1 | 19-May-11 | 1-Apr-13 | 1 | 1 | 1 |
1 | 19-May-11 | 1-Apr-13 | 2 | 1 | 1 |
1 | 19-May-11 | 1-Apr-13 | 3 | 1 | 1 |
1 | 19-May-11 | 1-Apr-13 | 4 | 1 | 1 |
2 | 13-Apr-15 | 15-May-15 | 1 | 2 | 1 |
2 | 13-Apr-15 | 15-May-15 | 2 | 2 | 1 |
3 | 8-Feb-17 | 15-Feb-17 | 1 | 3 | 1 |
3 | 8-Feb-17 | 15-Feb-17 | 2 | 3 | 1 |
4 | 31-Oct-13 | 13-Nov-13 | 1 | 4 | 1 |
5 | 31-Jul-12 | 27-Aug-12 | 1 | 5 | 1 |
6 | 27-Feb-08 | 28-Mar-13 | 1 | 6 | 1 |
6 | 27-Feb-08 | 28-Mar-13 | 2 | 6 | 1 |
6 | 27-Feb-08 | 28-Mar-13 | 3 | 6 | 1 |
7 | 14-Feb-14 | 24-Feb-14 | 1 | 7 | 1 |
8 | 9-Apr-14 | 16-Apr-14 | 1 | 8 | 1 |
9 | 18-Mar-14 | 10-Apr-14 | 1 | 9 | 1 |
10 | 2-Jul-12 | 24-Jul-12 | 1 | 10 | 1 |
10 | 17-Dec-12 | 8-Jan-13 | 1 | 11 | 2 |
10 | 2-Jul-14 | 11-Jul-14 | 1 | 12 | 3 |
Thanks for any guidance!
Regards,
Jenefer
Comment