I have a categorical variable program_value for a given health services used on that date. Ex. someone might have 1/1/22 program_value = hospital, 1/3/22 program_value = gp, 1/5/22 program_value=hospital
I want to tag the first appearance of "hospital" for each id. I'll be using this to compare service use before and after first hospital.
This is what didn't work:
gen prog_hospital=1 if program_value=="hospital"
egen first_hospital=tag(prog_hospital)
One more layer is that the timeframe resets every 30 days, so a hospital on 1/5/22 and 2/7/22 would both be first hospital, but if it were 1/5/22 and 1/7/22, only the 1/5 would be tagged as first hospital.
variables:
id = subject id
program_value = health service (hospital, gp, outpatient, detox)
date = date of health service use
I want to tag the first appearance of "hospital" for each id. I'll be using this to compare service use before and after first hospital.
This is what didn't work:
gen prog_hospital=1 if program_value=="hospital"
egen first_hospital=tag(prog_hospital)
One more layer is that the timeframe resets every 30 days, so a hospital on 1/5/22 and 2/7/22 would both be first hospital, but if it were 1/5/22 and 1/7/22, only the 1/5 would be tagged as first hospital.
variables:
id = subject id
program_value = health service (hospital, gp, outpatient, detox)
date = date of health service use

Comment