Announcement

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

  • Diff-in-diff and time-varying covariates

    I am aware there are issues when controlling for time-varying covariates in a diff-in-diff setting.
    However, I am wondering whether it would make sense to include (modified) covariates which values vary over time only during the pre-treatment periods but then become fixed at the pre-treatment average in the post-treatment periods.
    I am thinking of covariates that may drive the treatment assignment and at the same time may be affected by the treatment.
    By replacing the post-treatment values with the pre-treatment average, shouldn't we avoid the bad control problem?
    Tagging some diff-in-diff experts below
    Clyde Schechter Jared Greathouse
    Last edited by Lukas Lang; 28 Jan 2025, 09:55.
    ------
    I use Stata 17

  • #2
    To increase the chances of a reply I will make the following example:

    Code:
    *Load database
    use "http://www.princeton.edu/~otorres/WDI.dta", clear
    
    *Creating the before/after dummy variable: 0 = before, 1 =after
    gen after = (year >= 2009) if !missing(year)
    
    *For the example in this document, the treated countries were saved in a separate fake Stata dataset containing a variable "treated" = 1. Below we merge that file to have the treatment variable.
    merge m:1 country using "http://www.princeton.edu/~otorres/Treated.dta", gen(merge1)
    
    *The untreated units will have a missing value (".")
    replace treated = 0 if treated == .
    
    *Create the diff-in-diff indicator
    gen did = after * treated
    
    * Create a labeled numeric variable for the grouping or panel variable. This is needed for Stata commands to identify the panels in the data.
    encode country, gen(country1)
    
    *Set data as panel data (only for use with `xt' commands).
    xtset country1 year
    
    *did without covariate
    xtdidregress (gdppc) (did), group(country1) time(year)
    
    *did with covariate
    xtdidregress (gdppc labor) (did), group(country1) time(year)
    
    *pre-treatment time-varying covariate
    bys country1: egen labor_mean=mean(labor) if after==0
    gsort country -labor_mean
    bys country1: replace labor_mean=labor_mean[_n-1] if labor_mean==.
    sort country year
    gen labor_pretreat=labor if after==0
    replace labor_pretreat=labor_mean if after==1
    drop labor_mean
    
    *did with pre-treatment time-varying covariate
    xtdidregress (gdppc labor_pretreat) (did), group(country1) time(year)
    Does controlling for 'labor_pretreat' avoid the potential bad control problem because of the potential (post-treatment) effect of the treatment on labor?

    Would you consider this an econometrically valid solution if you thought that labor pre-treatment trends could impact the chance of receiving the treatment?
    ------
    I use Stata 17

    Comment

    Working...
    X