Announcement

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

  • Obtaining DD Predictions

    Hey everyone. I'll be teaching intro to stats for undergrads this Fall semester for policy students, and the last stats topic we cover is difference-in-differences. I begin by showing DD as a simplified regression estimator, and then I show how we can use Stata to automate the process. I want to get the counterfactual predictions produced by DD for the state of California. My current code is
    Code:
    clear *
    
    import delim "https://raw.githubusercontent.com/OscarEngelbrektson/SyntheticControlMethods/master/examples/datasets/smoking_data.csv", clear
    
    g treat = cond(state=="California",1,0)
    
    g post = cond(year > 1988,1,0)
    
    egen id = group(state)
    
    xtset id year, y
    
    
    reg cig i.treat##i.post, vce(cl id)
    
    predict cf
    This is fine, as we get the DD coefficient, the ATT. But, I want the actual counterfactual prediction line for California, our treated unit, and naturally this is not what predict returns in this case because of the interaction term.

    Getting the counterfactual prediction line is simple enough if we re-express DD as

    Code:
    clear *
    cls
    import delim "https://raw.githubusercontent.com/OscarEngelbrektson/SyntheticControlMethods/master/examples/datasets/smoking_data.csv", clear
    egen id = group(state)
    keep cig id year
    
    reshape wide cig, i(year) j(id)
    
    order cigsale3, a(year)
    
    egen ymean = rowmean(cigsale1-cigsale39)
    
    keep year cigsale3 ymean
    
    constraint define 1 ymean = 1
    
    cnsreg cigsale3 ymean if year < 1989, constraints(1)
    
    predict cf
    
    line cig cf year , lcol(black blue) // if year < 1989
    , but I figured there's got to be another way to derive the counterfactual using the interaction term approach (since that's what the students who choose to use DD for their papers would be doing anyways, instead of needing to fiddle with reshape and cnsreg). How might I do this? I must confess I've never had to do this before in Stata.

  • #2
    can you use generate and just write the equation out (using the _b[] ) and zero out the interaction?

    Comment


    • #3
      Code:
      g cf2 = _b[_cons] + _b[1.treat]*treat + _b[1.post]*post 
      list cf cf2 if treat

      Comment

      Working...
      X