Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create a first.treat for DID with multiple periods

    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
    Click image for larger version

Name:	sample_data.png
Views:	1
Size:	134.6 KB
ID:	1634932

  • #2
    Identify first year of treatment,
    Code:
    bys lgacodes (dummy): egen first_treat = min(year) if dummy
    Replace missing values with nonmissing,
    Code:
    bys lgacodes (first_treat): replace first_treat = first_treat[1]

    Comment

    Working...
    X