Hi everyone!
I am new to STATA and I need help to generate a new variable (actually two, but I assume I need to do this in two steps) based on three existing variables. Two of the excising variables are dates.
The current variables are 'event' (event at any timepoint, binary), 'date_of_event' and 'date_of_inclusion'.
I wish to divide the 'event' variable into two new variables whether or not the event happened before or after inclusion into a cohort.
The following codes put every observation from 'event' in the 'event_before' and none in the 'event_after', and I can't seem to fix it.
*string dates converted to STATA dates
generate stata_eventdate = date(date_of_event, "DMY")
format stata_eventdate %td
generate stata_inclusiondate = date(date_of_inclusion, "DMY")
format stata_inclusiondate %td
generate event_before = 1 if event ==1 & stata_eventdate <= stata_inclusiondate
replace event_before = 0 if missing(event_before)
generate event_after = 1 if event ==1 & stata_eventdate > stata_inclusiondate
replace event_after = 0 if missing(event_after)
Thank you so much!
I am new to STATA and I need help to generate a new variable (actually two, but I assume I need to do this in two steps) based on three existing variables. Two of the excising variables are dates.
The current variables are 'event' (event at any timepoint, binary), 'date_of_event' and 'date_of_inclusion'.
I wish to divide the 'event' variable into two new variables whether or not the event happened before or after inclusion into a cohort.
The following codes put every observation from 'event' in the 'event_before' and none in the 'event_after', and I can't seem to fix it.
*string dates converted to STATA dates
generate stata_eventdate = date(date_of_event, "DMY")
format stata_eventdate %td
generate stata_inclusiondate = date(date_of_inclusion, "DMY")
format stata_inclusiondate %td
generate event_before = 1 if event ==1 & stata_eventdate <= stata_inclusiondate
replace event_before = 0 if missing(event_before)
generate event_after = 1 if event ==1 & stata_eventdate > stata_inclusiondate
replace event_after = 0 if missing(event_after)
Thank you so much!

Comment