I am new to Stata and looking to efficiently set up time-to-event variables for the time to event considering competing risks and the multi-level event variable. This will be used to graph CIFs with competing events (death).
My question is if there is an efficient way to create these variables using long-data if the outcomes are separated into 3 separate vars, and time is days from index date
I was able to clumsily work my way through this using with a long series of "replace z = x if x<=y" commands, but I am hesitant to trust that data.
My data is set up something like (made up on the spot):
Code:
Example
id | desired_outcome | outc_date | death_date | censor_date |
1 | 0 | 7 | 242 | 100 |
1 | 0 | 10 | 242 | 100 |
1 | 1 | 15 | 242 | 100 |
1 | 1 | 20 | 242 | 100 |
2 | 1 | 44 | . | 30 |
2 | 1 | 55 | . | 30 |
3 | 1 | 52 | . | 30 |
3 | 0 | 5 | 25 | 30 |
3 | 0 | 10 | 25 | 30 |
3 | 0 | 15 | 25 | 30 |
3 | 0 | 20 | 25 | 30 |
Example code: bysort id: egen outc_1 = min(outc_date) replace outc_1 = censor_date if missing(outc_1) *series of "replace if less than" lines* gen outc_1_type = . replace gen outc_1_type = 0 if gen outc_1==censor_date replace gen outc_1_type = 1 if gen outc_1==outc_date replace gen outc_1_type = 2 if gen outc_1==death_date
Code:
id | desired_outcome | outc_date | death_date | censor_date | outc_1 | outc_1_type |
1 | 1 | 15 | 242 | 100 | 15 | 1 |
2 | 1 | 44 | . | 30 | 30 | 0 |
3 | 0 | 20 | 25 | 30 | 25 | 2 |
Thank you so much.
0 Response to Setting up time-to-first-event variables
Post a Comment