-------------
      name:  <unnamed>
       log:  /Users/manuelbagues/Dropbox/teaching/2022 - Aalto - Applied Microeconometrics/problem sets/ps3/Dif-in-dif/log ps3.smcl
  log type:  smcl
 opened on:  21 Sep 2022, 20:56:31

.
. clear

. use https://manuelbagues.com/teaching/mpdta.dta
(Written by R.              )

.
.
.
. gen treated=0

. replace treated=1 if year>=first_treat & first_treat!=0
(291 real changes made)

.
. // Estimates using the two-way fixed-effects model
.
. *ssc install reghdfe
.
. reghdfe lemp lpop treated, absorb(year countyreal) cluster(countyreal)
note: lpop is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
(MWFE estimator converged in 2 iterations)
note: lpop omitted because of collinearity

HDFE Linear regression                            Number of obs   =      2,500
Absorbing 2 HDFE groups                           F(   1,    499) =       7.59
Statistics robust to heteroskedasticity           Prob > F        =     0.0061
                                                  R-squared       =     0.9932
                                                  Adj R-squared   =     0.9915
                                                  Within R-sq.    =     0.0042
 Number of clusters (countyreal)  =        500    Root MSE        =     0.1391

(Std. err. adjusted for 500 clusters in countyreal)
-------------+----------------------------------------------------------------
             |               Robust
         lemp | Coefficient   std. err.       t    P>|t|      [95% con f. interval]
-------------+----------------------------------------------------------------
        lpop |           0   (omitted)
     treated |   -.0365489    .0132652     -2.76    0.006     -.0626114    -.0104865
       _cons |    5.776771    .0015441   3741.28    0.000      5.773737     5.779804
-------------+----------------------------------------------------------------

Absorbed degrees of freedom:
 -------------+---------------------------------------+
  Absorbed FE | Categories  - Redundant   = Num. Coefs |
 -------------+---------------------------------------+
         year |         5          0           5      |
   countyreal |       500        500           0    * |
 -------------+---------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. *minor note: in the dataset there is no variation in population over time, which explains why the variable drops if we include fixed effects
.
.
. // Estimates with never-treated units as the control group
. csdid lemp lpop, i(countyreal) t(year) g(first_treat)
............
Difference-in-difference with Multiple Time Periods

                                                         Number of obs    = 2,500
Outcome model  : weighted least squares
Treatment model: inverse probability tilting
-------------+----------------------------------------------------------------
             | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
g2004        |
 t_2003_2004 |   -.0145329    .0221264     -0.66    0.511        -.0579     .0288341
 t_2003_2005 |   -.0764267    .0286661     -2.67    0.008     -.1326113    -.0202422
 t_2003_2006 |   -.1404536     .035373     -3.97    0.000     -.2097834    -.0711239
 t_2003_2007 |   -.1069093    .0328863     -3.25    0.001     -.1713652    -.0424533
-------------+----------------------------------------------------------------
g2006        |
 t_2003_2004 |   -.0006112     .022198     -0.03    0.978     -.0441185     .0428961
 t_2004_2005 |    -.006267     .018481     -0.34    0.735      -.042489     .0299551
 t_2005_2006 |    .0009473    .0193812      0.05    0.961     -.0370391     .0389337
 t_2005_2007 |   -.0413123    .0197171     -2.10    0.036     -.0799571    -.0026674
-------------+----------------------------------------------------------------
g2007        |
 t_2003_2004 |    .0266993    .0140628      1.90    0.058     -.0008633     .0542619
 t_2004_2005 |   -.0045906    .0157101     -0.29    0.770     -.0353818     .0262007
 t_2005_2006 |   -.0284515    .0181775     -1.57    0.118     -.0640787     .0071758
 t_2006_2007 |   -.0287821    .0162333     -1.77    0.076     -.0605988     .0030347
-------------+----------------------------------------------------------------
Control: Never Treated

See Callaway and Sant'Anna (2021) for details

.
. // Plot results for the 2004 group
. csdid_plot, group(2004)

. addplot: , ${color_opts} legend(off) title("2004, control never-treated")

. graph export "2004_comp_never_treated.png", replace


file
/Users/manuelbagues/Dropbox/teaching/2022 - Aalto - Applied Microeconometrics/problem sets/ps3/Dif-in-dif/2004_comp_never_treated.png{rm}
saved as
PNG
format


.
.
. // Plot results for the 2006 group
. csdid_plot, group(2006)

. addplot: , ${color_opts} legend(off) title("2006, control never-treated")

. graph export "2006_comp_never_treated.png", replace


file
/Users/manuelbagues/Dropbox/teaching/2022 - Aalto - Applied Microeconometrics/problem sets/ps3/Dif-in-dif/2006_comp_never_treated.png{rm}
saved as
PNG
format


.
.
. // Aggregate result for ATE
. estat simple
Average Treatment Effect on Treated
-------------+----------------------------------------------------------------
             | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         ATT |   -.0417577    .0115008     -3.63    0.000     -.0642989    -.0192165
-------------+----------------------------------------------------------------

.
. // Test for pretrend
. estat pretrend
Pretrend Test. H0 All Pre-treatment are equal to 0
chi2(5) =     6.8436
p-value  =     0.2325

.
.
. // Estimates with not-yet-treated units as the control group
. csdid lemp lpop, i(countyreal) t(year) g(first_treat) notyet
............
Difference-in-difference with Multiple Time Periods

                                                         Number of obs    = 2,500
Outcome model  : weighted least squares
Treatment model: inverse probability tilting
-------------+----------------------------------------------------------------
             | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
g2004        |
 t_2003_2004 |   -.0211832     .021648     -0.98    0.328     -.0636124      .021246
 t_2003_2005 |   -.0816037    .0283406     -2.88    0.004     -.1371504    -.0260571
 t_2003_2006 |   -.1381927    .0342272     -4.04    0.000     -.2052767    -.0711087
 t_2003_2007 |   -.1069093    .0328863     -3.25    0.001     -.1713652    -.0424533
-------------+----------------------------------------------------------------
g2006        |
 t_2003_2004 |   -.0074923    .0218276     -0.34    0.731     -.0502736      .035289
 t_2004_2005 |   -.0046434    .0182795     -0.25    0.799     -.0404705     .0311837
 t_2005_2006 |    .0086951    .0168368      0.52    0.606     -.0243044     .0416945
 t_2005_2007 |   -.0413123    .0197171     -2.10    0.036     -.0799571    -.0026674
-------------+----------------------------------------------------------------
g2007        |
 t_2003_2004 |    .0266993    .0140628      1.90    0.058     -.0008633     .0542619
 t_2004_2005 |   -.0045906    .0157101     -0.29    0.770     -.0353818     .0262007
 t_2005_2006 |   -.0284515    .0181775     -1.57    0.118     -.0640787     .0071758
 t_2006_2007 |   -.0287821    .0162333     -1.77    0.076     -.0605988     .0030347
-------------+----------------------------------------------------------------
Control: Not yet Treated

See Callaway and Sant'Anna (2021) for details

.
. // Plot results for the 2004 group
. csdid_plot, group(2004)

. addplot: , ${color_opts} legend(off) title("2006, control not-yet-treated")

. graph export "2004_comp_not-yet_treated.png", replace


file
/Users/manuelbagues/Dropbox/teaching/2022 - Aalto - Applied Microeconometrics/problem sets/ps3/Dif-in-dif/2004_comp_not-yet_treated.png{rm}
saved as
PNG
format


.
. // Plot results for the 2006 group
. csdid_plot, group(2006)

. addplot: , ${color_opts} legend(off) title("2006, control not-yet-treated")

. graph export "2006_comp_not-yet_treated.png", replace


file
/Users/manuelbagues/Dropbox/teaching/2022 - Aalto - Applied Microeconometrics/problem sets/ps3/Dif-in-dif/2006_comp_not-yet_treated.png{rm}
saved as
PNG
format


.
. // Aggregate result for ATE
. estat simple
Average Treatment Effect on Treated
-------------+----------------------------------------------------------------
             | Coefficient   Std. err.       z    P>|z|      [95% con f. interval]
-------------+----------------------------------------------------------------
         ATT |   -.0413502    .0114256     -3.62    0.000      -.063744    -.0189564
-------------+----------------------------------------------------------------

.
. // Test for pretrend
. estat pretrend
Pretrend Test. H0 All Pre-treatment are equal to 0
chi2(5) =     6.8661
p-value  =     0.2308

.
end of do-file

. log close
      name:  <unnamed>
       log:  /Users/manuelbagues/Dropbox/teaching/2022 - Aalto - Applied Microeconometrics/problem sets/ps3/Dif-in-dif/log ps3.smcl
  log type:  smcl
 closed on:  21 Sep 2022, 20:57:51
-------------