Hello, I am using Stata 15
I am trying to create a grouping variable that indicates whether participants were seen within days_to_dt1_pt <15 days , 15- 90 days and > 90 days. I am interested in only the days to the first treatment days_to_dt1_lpt). So I am not interested, for example, in the 16 and 30 for participant 1 as they would be categorized as < 15 . I want to only have one possible category for each participant. I can not figure out how to do this without creating a value for each row of data. For participant 2, they would be in the 15-90 day category but it would be recorded twice--again what I don't want.
My data look like:
id month days_to_ dt1_pt
1 1 10
1 2 16
1 3 30
1 4 .
1 5 .
2 1 .
2 2 46
2 3 50
2 4 .
What I tired is to create a 1 for each time the patient is in one of the categories. But as you can see below, code 2 would return a value for month 2 and 3 which i don't want. I am not sure how to handle this.
capture drop
gen early_vs_delay = .
replace early_vs_delay = 1 if days_to_dt1_pt < 15
capture drop early_vs_delay_1
gen early_vs_delay_1 = .
replace early_vs_delay_1 = 1 if days_to_dt1_pt > 14 & days_to_dt1_pt < 91
capture drop early_vs_delay_2
gen early_vs_delay_2 = .
replace early_vs_delay_2 = 1 if days_to_dt1_pt > 90 & days_to_dt1_pt < 1000
Then I tried to combine:
capture drop early_vs_delay_3 // this is to creatE a variable from combining the ones for above.
gen early_vs_delay_3 = .
replace early_vs_delay_3 = 1 if early_vs_delay ==1 // 2 week or less
replace early_vs_delay_3 = 2 if early_vs_delay_1 == 1 // 2 weeks to 90 days
replace early_vs_delay_3 = 0 if early_vs_delay_2 == 1
Please let me know if this information is sufficient or more detail is needed.
Thanks.
Jake
I am trying to create a grouping variable that indicates whether participants were seen within days_to_dt1_pt <15 days , 15- 90 days and > 90 days. I am interested in only the days to the first treatment days_to_dt1_lpt). So I am not interested, for example, in the 16 and 30 for participant 1 as they would be categorized as < 15 . I want to only have one possible category for each participant. I can not figure out how to do this without creating a value for each row of data. For participant 2, they would be in the 15-90 day category but it would be recorded twice--again what I don't want.
My data look like:
id month days_to_ dt1_pt
1 1 10
1 2 16
1 3 30
1 4 .
1 5 .
2 1 .
2 2 46
2 3 50
2 4 .
What I tired is to create a 1 for each time the patient is in one of the categories. But as you can see below, code 2 would return a value for month 2 and 3 which i don't want. I am not sure how to handle this.
capture drop
gen early_vs_delay = .
replace early_vs_delay = 1 if days_to_dt1_pt < 15
capture drop early_vs_delay_1
gen early_vs_delay_1 = .
replace early_vs_delay_1 = 1 if days_to_dt1_pt > 14 & days_to_dt1_pt < 91
capture drop early_vs_delay_2
gen early_vs_delay_2 = .
replace early_vs_delay_2 = 1 if days_to_dt1_pt > 90 & days_to_dt1_pt < 1000
Then I tried to combine:
capture drop early_vs_delay_3 // this is to creatE a variable from combining the ones for above.
gen early_vs_delay_3 = .
replace early_vs_delay_3 = 1 if early_vs_delay ==1 // 2 week or less
replace early_vs_delay_3 = 2 if early_vs_delay_1 == 1 // 2 weeks to 90 days
replace early_vs_delay_3 = 0 if early_vs_delay_2 == 1
Please let me know if this information is sufficient or more detail is needed.
Thanks.
Jake
Comment