Announcement

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

  • Unexpected issues with xtdidregress

    I wanted to ensure that xtdidregress was consistent with the "old-fashioned" way of running differences in differences. To do this, I generated a simulated dataset and ran some regressions (see code).

    I started by verifying that `reg` and `reghdfe` produced consistent results. To my surprise, in this toy dataset, xtdidregress wouldn't run due to collinearity, even when I included the `nogteffects` option (so that there should be nothing to be co-linear with)!

    What am I doing wrong?

    Code:
    clear *
    set seed 1234
    local N 50
    
    set obs `N'
    gen id = _n
    
    gen x = rnormal()
    expand 2, gen(t)
    label val t
    
    * y is independent of x for t = 0
    * y is related to x at t = 1
    gen y = rnormal() + (t==1) * x
    
    xtset id t
    
    estimates clear
    eststo: reghdfe y c.x##i.t, a(t id)
    
    eststo: reg D.y x
    
    esttab *, keep(1.t#c.x x)
    
    * STATA complains about collinearity
    xtdidregress (y) (x, continuous), group(id) time(t) nogteffects
    
    /*
    model is not identified
        The treatment variable x was omitted because of collinearity.
    
    */
    
    * Issue isn't with the continuous treatment
    egen x_bin = cut(x), group(2)
    xtdidregress (y) (x_bin), group(id) time(t) nogteffects

  • #2
    Dear Geoff,

    What goes in the second parenthesis should be the observation level treatment variable. In your case, -1.t#c.x-. Try for example:

    Code:
    generate treat = 1.t#c.x
    xtdidregress (y) (treat, continuous), group(id) time(t)
    This should give you what you are expecting.

    -xtdidregress- runs -xtreg..., fe-. When -xtreg, fe- drops the observation level treatment from the model, the command refuses to proceed. In your case, with -nogteffects-:

    Code:
    . xtreg y x, fe vce(cluster id)
    note: x omitted because of collinearity.
    
    Fixed-effects (within) regression               Number of obs     =        100
    Group variable: id                              Number of groups  =         50
    
    R-squared:                                      Obs per group:
         Within  =      .                                         min =          2
         Between =      .                                         avg =        2.0
         Overall =      .                                         max =          2
    
                                                    F(0, 49)          =          .
    corr(u_i, Xb) =      .                          Prob > F          =          .
    
                                        (Std. err. adjusted for 50 clusters in id)
    ------------------------------------------------------------------------------
                 |               Robust
               y | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
               x |          0  (omitted)
           _cons |  -.0147431          .        .       .            .           .
    -------------+----------------------------------------------------------------
         sigma_u |  .79912424
         sigma_e |  1.2827061
             rho |  .27960503   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------

    Comment


    • #3
      Thanks for the clarification. This was very helpful

      Comment

      Working...
      X