Hi everyone,
I'm working with a panel dataset where each row corresponds to a monthly observation for a subject. One of the variables, months_on_treatment, indicates the month when a treatment was prescribed and shows the duration of the treatment in months. The column months_fu refers to the current observation in months.
Here's my current problem: I need to carry over the treatment duration data only for the months where the treatment is actually supposed to be active, post-prescription. However, I am struggling to apply this only to the relevant months for each subject after the initial prescription observation.
Could someone help me devise a Stata code or suggest a method to correctly propagate the treatment duration data across the relevant months?
This is an example of how my data looks:
What I need is to generate the "on_treatment" variable:
Thank you in advance for your help!
I'm working with a panel dataset where each row corresponds to a monthly observation for a subject. One of the variables, months_on_treatment, indicates the month when a treatment was prescribed and shows the duration of the treatment in months. The column months_fu refers to the current observation in months.
Here's my current problem: I need to carry over the treatment duration data only for the months where the treatment is actually supposed to be active, post-prescription. However, I am struggling to apply this only to the relevant months for each subject after the initial prescription observation.
Could someone help me devise a Stata code or suggest a method to correctly propagate the treatment duration data across the relevant months?
This is an example of how my data looks:
| id | treat_duration | months_fu |
| 1 | 5 | 0 |
| 1 | . | 1 |
| 1 | . | 2 |
| 1 | . | 3 |
| 1 | . | 4 |
| 1 | . | 5 |
| 1 | . | 6 |
| 1 | . | 7 |
| 1 | . | 8 |
| 1 | . | 9 |
| 1 | 4 | 10 |
| 1 | . | 11 |
| 1 | . | 12 |
| 1 | . | 13 |
| 1 | . | 14 |
| 1 | , | 15 |
| 1 | . | 16 |
| 1 | . | 17 |
| 1 | . | 18 |
| 1 | . | 19 |
| 1 | . | 20 |
| 1 | 3 | 21 |
| 1 | . | 22 |
| 1 | . | 23 |
| 1 | . | 24 |
| 1 | . | 25 |
| id | treat_duration | months_fu | on_treatment |
| 1 | 5 | 0 | yes |
| 1 | . | 1 | yes |
| 1 | . | 2 | yes |
| 1 | . | 3 | yes |
| 1 | . | 4 | yes |
| 1 | . | 5 | no |
| 1 | . | 6 | no |
| 1 | . | 7 | no |
| 1 | . | 8 | no |
| 1 | . | 9 | no |
| 1 | 4 | 10 | yes |
| 1 | . | 11 | yes |
| 1 | . | 12 | yes |
| 1 | . | 13 | yes |
| 1 | . | 14 | no |
| 1 | , | 15 | no |
| 1 | . | 16 | no |
| 1 | . | 17 | no |
| 1 | . | 18 | no |
| 1 | . | 19 | no |
| 1 | . | 20 | no |
| 1 | 3 | 21 | yes |
| 1 | . | 22 | yes |
| 1 | . | 23 | yes |
| 1 | . | 24 | no |
| 1 | . | 25 | no |

Comment