Dear Statalist,
I'm working with patient hospitalization data and hoping to group together multiple separations that occur on sequential dates into the same overall admission
Specifically, I'm hoping to create a new variable that looks like "desired_var" from the given data for each individual patient

Using the following data:
I've tried the following code, but it doesn't create the variable I'm hoping to create
bysort id (date_end date_start): gen desiredvar = _n if dummy_overlap==1
Kind regards,
Ben
I'm working with patient hospitalization data and hoping to group together multiple separations that occur on sequential dates into the same overall admission
Specifically, I'm hoping to create a new variable that looks like "desired_var" from the given data for each individual patient
Using the following data:
Code:
input id date_start date_end dummy_overlap 1 100 200 1 1 200 300 1 1 500 600 . 1 700 800 . 1 900 1000 . 1 1100 1200 1 1 1200 1300 1 1 1300 1400 1 1 1700 1800 . 1 1900 2000 . 1 2200 2300 . 1 2400 2500 1 1 2500 2600 1 1 2600 2700 1 2 100 200 1 2 200 300 1 2 500 600 . 2 700 800 . 2 900 1000 . 2 1100 1200 1 2 1200 1300 1 2 1300 1400 1 2 1700 1800 . 2 1900 2000 . 2 2200 2300 . 2 2400 2500 1 2 2500 2600 1 2 2600 2700 1 end
I've tried the following code, but it doesn't create the variable I'm hoping to create
bysort id (date_end date_start): gen desiredvar = _n if dummy_overlap==1
Kind regards,
Ben
Comment