I am trying to create a group variable first_treat indicating the first year when each unit becomes treated, to perform a DID analysis. There is variation in treatment timing, and therefore I need to define a variable "first-treat" reporting for each ID the year when they first became treated (treatment = 0 if not treated, 1 otherwise). In case the units are never treated, the value of first_treat will be zero. I report below a simplified dataframe: I have the variables ID, Year, and Treatment. I need to create the variable first.treat as follows.
What is the best way to do this in stata? Thankyou in advance.
a | 2016 | 0 | 2017 |
a | 2017 | 1 | 2017 |
a | 2018 | 1 | 2017 |
b | 2016 | 1 | 2016 |
b | 2017 | 1 | 2016 |
b | 2018 | 1 | 2016 |
c | 2016 | 0 | 2018 |
c | 2017 | 0 | 2018 |
c | 2018 | 1 | 2018 |
d | 2016 | 0 | 0 |
d | 2017 | 0 | 0 |
d | 2018 | 0 | 0 |
What is the best way to do this in stata? Thankyou in advance.
Comment