Hi everyone,

I have a panel data (1960 to 1980) with multiple locations (lgacodes) and am trying to create a column with the first year of treatment for each location (to do Difference-in-Differences with multiple periods). I used this code:

bysort lgacodes: replace first_treat=min( year1_lga) if dummy_general==1

but it didn't work, so I used:

bysort lgacodes: replace first_treat= year1_lga if dummy_general==1

instead.

Now, I believe I have to create a foreach loop to replace 'first_treat' with the min (year1_lga) for each lgacodes, but not sure how to do it. Could you please help?

Many thanks,

Here is a sample of my data Array