Hello,
I am working with panel data, and I am trying to create binary indicators for the first year a unit was treated and then indicators equal to 1 for the year prior/after to treatment, 2 years prior/after to treatment, etc. I want to create an indicator for 5+ years before/after treatment.
For 5+ years after treatment, I use the following code:
where yeart is a dummy equal to 1 in the year that the treatment turns on, and tplus is for all years 5+.
I'm not sure how to approach the 5+ years before treatment, however, as when I try the analogous code as below:
this results in only the 5th and 6th years before treatment being coded as 1 rather than all other previous years.
Any advice on how to revise this code would be appreciated. Thank you.
I am working with panel data, and I am trying to create binary indicators for the first year a unit was treated and then indicators equal to 1 for the year prior/after to treatment, 2 years prior/after to treatment, etc. I want to create an indicator for 5+ years before/after treatment.
For 5+ years after treatment, I use the following code:
Code:
gen tplus5=L.5yeart gen tplus=tplus5 by uniqueid (year), sort: replace tplus = max(tplus, tplus[_n-1])
I'm not sure how to approach the 5+ years before treatment, however, as when I try the analogous code as below:
Code:
gen tminus5= F5.yeart gen tminus=tminus5 by uniqueid (year), sort: replace tminus = max(tminus, tminus[_n+1])
Any advice on how to revise this code would be appreciated. Thank you.