Announcement

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

  • writing the 'didregress'-command as a 'reg'-command

    Hi all

    To better understand what is going on in the 'didregress'-command, I want to be able to write it up as a reg-command. I have tried two procedures of doing this. The coefficients obtained are the same as in 'didregress' but the standard errors differ:

    Code:
    use https://www.stata-press.com/data/r17/hospdd, clear
    
    didregress (satis) (procedure), group(hospital) time(month)
    
    *procedure 1
    recode hospital (1/18=1 "Treated") (19/46=0 "Control"), gen(treated)
    reg satis treated##procedure i.month, vce(cluster hospital)
    
    *procedure 2
    recode month (1/3 = 0 "Pre") (4/7 = 1 "Post"), gen(period)
    reg satis i.period##i.treated, vce(cluster hospital)
    In a previous post Enrique Pinzon (StataCorp) explained that the standard errors in procedure 2 differed because it was a 2-by-2 DiD which differed from the generalized/two-way fixed effect DiD used in 'didregress'. The 'reg' in procedure 1 is my best attempt of writing a generalized DiD, but the standard errors differ from those obtained by 'didregress'. Maybe this is because the standard errors of month is also calculated? Could someone kindly explain how to write the 'didregress' using 'reg'?

  • #2
    Code:
    use https://www.stata-press.com/data/r17/hospdd, clear
    didregress (satis) (procedure), group(hospital) time(month)
    regress satis i.procedure i.hospital i.month, cluster(hospital)
    Res.:

    Code:
    . didregress (satis) (procedure), group(hospital) time(month)
    
    Number of groups and treatment time
    
    Time variable: month
    Control:       procedure = 0
    Treatment:     procedure = 1
    -----------------------------------
                 |   Control  Treatment
    -------------+---------------------
    Group        |
        hospital |        28         18
    -------------+---------------------
    Time         |
         Minimum |         1          4
         Maximum |         1          4
    -----------------------------------
    
    Difference-in-differences regression                     Number of obs = 7,368
    Data type: Repeated cross-sectional
    
                                   (Std. err. adjusted for 46 clusters in hospital)
    -------------------------------------------------------------------------------
                  |               Robust
            satis | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    --------------+----------------------------------------------------------------
    ATET          |
        procedure |
    (New vs Old)  |   .8479879   .0321121    26.41   0.000     .7833108     .912665
    -------------------------------------------------------------------------------
    Note: ATET estimate adjusted for group effects and time effects.
    
    . 
    . regress satis i.procedure i.hospital i.month, cluster(hospital)
    
    Linear regression                               Number of obs     =      7,368
                                                    F(6, 45)          =          .
                                                    Prob > F          =          .
                                                    R-squared         =     0.5333
                                                    Root MSE          =     .72384
    
                                  (Std. err. adjusted for 46 clusters in hospital)
    ------------------------------------------------------------------------------
                 |               Robust
           satis | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
       procedure |
            New  |   .8479879   .0321121    26.41   0.000     .7833108     .912665
                 |
        hospital |
              2  |   .4085664   2.43e-14  1.7e+13   0.000     .4085664    .4085664
              3  |   .5336248   2.43e-14  2.2e+13   0.000     .5336248    .5336248
              4  |   .2275102   2.43e-14  9.4e+12   0.000     .2275102    .2275102
              5  |  -.1453529   2.43e-14 -6.0e+12   0.000    -.1453529   -.1453529
              6  |   .4478634   2.43e-14  1.8e+13   0.000     .4478634    .4478634
              7  |   1.404416   2.46e-14  5.7e+13   0.000     1.404416    1.404416
              8  |   .0718758   2.43e-14  3.0e+12   0.000     .0718758    .0718758
              9  |  -1.518515   2.43e-14 -6.2e+13   0.000    -1.518515   -1.518515
             10  |   1.682845   2.44e-14  6.9e+13   0.000     1.682845    1.682845
             11  |   .2209653   2.43e-14  9.1e+12   0.000     .2209653    .2209653
             12  |  -.0953034   2.43e-14 -3.9e+12   0.000    -.0953034   -.0953034
             13  |   .4955931   2.43e-14  2.0e+13   0.000     .4955931    .4955931
             14  |   .2330426   2.43e-14  9.6e+12   0.000     .2330426    .2330426
             15  |  -.1444935   2.43e-14 -5.9e+12   0.000    -.1444935   -.1444935
             16  |   1.414268   2.43e-14  5.8e+13   0.000     1.414268    1.414268
             17  |   .4235429   2.43e-14  1.7e+13   0.000     .4235429    .4235429
             18  |   .1532761   2.43e-14  6.3e+12   0.000     .1532761    .1532761
             19  |  -.7453017   .0160561   -46.42   0.000    -.7776403   -.7129632
             20  |   .0473874   .0160561     2.95   0.005     .0150489     .079726
             21  |   1.194337   .0160561    74.39   0.000     1.161998    1.226676
             22  |   .7993153   .0160561    49.78   0.000     .7669768    .8316539
             23  |   .7017202   .0160561    43.70   0.000     .6693817    .7340588
             24  |   -.308126   .0160561   -19.19   0.000    -.3404646   -.2757875
             25  |   .6464736   .0160561    40.26   0.000     .6141351    .6788122
             26  |   .2142471   .0160561    13.34   0.000     .1819086    .2465857
             27  |  -.3986544   .0160561   -24.83   0.000     -.430993   -.3663159
             28  |   .7119953   .0160561    44.34   0.000     .6796568    .7443339
             29  |   .2485512   .0160561    15.48   0.000     .2162127    .2808898
             30  |   -.167922   .0160561   -10.46   0.000    -.2002606   -.1355835
             31  |   .5120848   .0160561    31.89   0.000     .4797462    .5444233
             32  |  -.3233456   .0160561   -20.14   0.000    -.3556842   -.2910071
             33  |  -.4539752   .0160561   -28.27   0.000    -.4863137   -.4216366
             34  |  -.0004123   .0160561    -0.03   0.980    -.0327509    .0319262
             35  |    .354111   .0160561    22.05   0.000     .3217724    .3864495
             36  |   2.138142   .0160561   133.17   0.000     2.105804    2.170481
             37  |   .1404036   .0160561     8.74   0.000      .108065    .1727421
             38  |   -.086806   .0160561    -5.41   0.000    -.1191445   -.0544674
             39  |  -.0234969   .0160561    -1.46   0.150    -.0558355    .0088416
             40  |   1.121533   .0160561    69.85   0.000     1.089195    1.153872
             41  |  -.1497346   .0160561    -9.33   0.000    -.1820731    -.117396
             42  |   .8811369   .0160561    54.88   0.000     .8487984    .9134755
             43  |  -.7724325   .0160561   -48.11   0.000    -.8047711    -.740094
             44  |    .034412   .0160561     2.14   0.038     .0020735    .0667506
             45  |  -.2137495   .0160561   -13.31   0.000     -.246088   -.1814109
             46  |   .0784915   .0160561     4.89   0.000     .0461529      .11083
                 |
           month |
       February  |  -.0096077   .0184317    -0.52   0.605    -.0467311    .0275158
          March  |   .0219686    .018251     1.20   0.235    -.0147907    .0587279
          April  |  -.0032839   .0221028    -0.15   0.883    -.0478013    .0412335
            May  |  -.0094027   .0232399    -0.40   0.688    -.0562103    .0374048
           June  |  -.0038375   .0190634    -0.20   0.841    -.0422332    .0345581
           July  |  -.0111941   .0230029    -0.49   0.629    -.0575244    .0351361
                 |
           _cons |   3.171657   .0172328   184.05   0.000     3.136948    3.206365
    ------------------------------------------------------------------------------
    
    .

    Comment


    • #3
      Thanks, Andrew Musau !

      Comment

      Working...
      X