Hi,
My dataset contains data on hospitalizations with participants each having multiple hospitalizations. I want to select the first hospitalization for each participant that meets certain diagnostic criteria. The diagnostic criteria variable (diag) is coded as 1-5. I am using a time variable (days between baseline assessment and hospitalization--labeled "caseday") to base what is considered the "first" hospitalization. I want the first hospitalization that is diag==1|2|3. IF participants have NO hospitalizations that are 1|2|3, then I want their first hospitalization that is either diag = 4|5|.
I'm using the following to select their first hosp that is 1|2|3.
duplicates tag id, generate(duplicate)
gen diag_include=1 if diag<4
egen dup_n = min(casedy) if diag_include==1 & duplicate!=0, by(id)
gen include=1 if dup_n==casedy
However, I'm getting stuck on how to pull in the cases where there was NO 1|2|3.
Any advice appreciated. Thanks
My dataset contains data on hospitalizations with participants each having multiple hospitalizations. I want to select the first hospitalization for each participant that meets certain diagnostic criteria. The diagnostic criteria variable (diag) is coded as 1-5. I am using a time variable (days between baseline assessment and hospitalization--labeled "caseday") to base what is considered the "first" hospitalization. I want the first hospitalization that is diag==1|2|3. IF participants have NO hospitalizations that are 1|2|3, then I want their first hospitalization that is either diag = 4|5|.
I'm using the following to select their first hosp that is 1|2|3.
duplicates tag id, generate(duplicate)
gen diag_include=1 if diag<4
egen dup_n = min(casedy) if diag_include==1 & duplicate!=0, by(id)
gen include=1 if dup_n==casedy
However, I'm getting stuck on how to pull in the cases where there was NO 1|2|3.
Any advice appreciated. Thanks
Comment