34 DiD
34 DiD
34 DiD
Difference in Differences
Using Stata
Chuck Huber
StataCorp
[email protected]
https://tinyurl.com/StataDID
Outline
• The Question
• An Intuitive Introduction
• Two Period, Two Groups Model
• Repeated Cross-Sectional Panel Data
• Longitudinal Panel Data
• More information
Outline
• The Question
• An Intuitive Introduction
• Two Period, Two Groups Model
• Repeated Cross-Sectional Panel Data
• Longitudinal Panel Data
• More information
A Conceptual Introduction
A Conceptual Introduction
A Conceptual Introduction
A Conceptual Introduction
A Conceptual Introduction
A Conceptual Introduction
A Conceptual Introduction
A Conceptual Introduction
A Conceptual Introduction
Outline
• The Question
• An Intuitive Introduction
• Two Period, Two Groups Model
• Repeated Cross-Sectional Panel Data
• Longitudinal Panel Data
• More information
The Two Period, Two Group Model
The Examples Dataset
.
. list state MLDA21_year year MLDA21 ///
> if year!=1980 & inlist(FIPS, 17,18,19) ///
> , sepby(state) nolabel noobs abbrev(18)
.
. list state MLDA21_year year MLDA21 time ///
> if year!=1980 & inlist(FIPS, 17,18,19) ///
> , sepby(state) nolabel noobs abbrev(18)
.
. list state MLDA21_year year MLDA21 time treated TimeTreat ///
> if year!=1980 & inlist(FIPS, 17,18,19) ///
> , sepby(state) nolabel noobs abbrev(18)
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
The Average Treatment Effect Among the Treated (ATET) is the coefficient
for TimeTreat.
The MLDA21 law caused a decrease of 4.6 people per 100,000 population
in the 18-20 year old age group between 1979 and 1981.
DiD Using regress
. regress mrate_agegrp i.time##i.treated, vce(cluster FIPS)
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
time#treated
1 1 -4.611695 3.32785 -1.39 0.173 -11.31433 2.090939
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
year
1980 -.5155614 2.882514 -0.18 0.859 -6.321242 5.29012
1981 -4.18646 3.313667 -1.26 0.213 -10.86053 2.487608
FIPS
2 10.37779 2.88e-13 3.6e+13 0.000 10.37779 10.37779
4 3.268883 2.88e-13 1.1e+13 0.000 3.268883 3.268883
5 5.474611 1.361131 4.02 0.000 2.733153 8.216069
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
year
1980 -.5155614 2.882514 -0.18 0.859 -6.321242 5.29012
1981 -4.18646 3.313667 -1.26 0.213 -10.86053 2.487608
FIPS
2 10.37779 2.88e-13 3.6e+13 0.000 10.37779 10.37779
4 3.268883 2.88e-13 1.1e+13 0.000 3.268883 3.268883
5 5.474611 1.361131 4.02 0.000 2.733153 8.216069
DiD Using regress
DiD Using didregress
Control Treatment
Group
FIPS 33 13
Time
Minimum 1979 1981
Maximum 1979 1981
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
ATET
TimeTreat
(1 vs 0) -4.611695 4.083392 -1.13 0.265 -12.83607 3.612679
Note: ATET estimate adjusted for group effects and time effects.
Checking the Parallel Trends Assumption
estat trendplots
Checking the Parallel Trends Assumption
. estat granger
Control Treatment
Group
FIPS 32 13
Time
Minimum 1979 1981
Maximum 1979 1981
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
ATET
TimeTreat
(1 vs 0) -5.140093 4.195906 -1.23 0.227 -13.59639 3.316199
Note: ATET estimate adjusted for covariates, group effects, and time effects.
Estimation of Standard Errors
Estimation of Standard Errors
errorweight(edtype) defines the error weight used to draw residuals from the wild bootstrap. edtype is one of rademacher (the
default), mammen, webb, normal, or gamma.
rademacher multiplies the residuals at each bootstrap replication with a randomly generated variable that takes the value
of 1 with probability 0.5 and the value of -1 with probability 0.5. errorweight(rademacher) is the default.
mammen multiplies the residuals at each bootstrap replication with a randomly generated variable that takes the value of 1
- phi with probability phi/sqrt{5} and phi otherwise, where phi = (1+sqrt{5})/2.
webb multiplies the residuals at each bootstrap replication with a randomly generated variable that takes the values
-sqrt{3/2}, -sqrt{2/2}, -sqrt{1/2}, sqrt{1/2}, sqrt{2/2}, and sqrt{3/2}, each with probability 1/6.
normal multiplies the residuals at each bootstrap replication with a randomly generated normal distribution variable with
the first four moments given by 0, 1, 0, and 3.
gamma multiplies the residuals at each bootstrap replication with a randomly generated gamma distribution variable with
shape parameter 4 and scale parameter 1/2.
blocksize(#) specifies that the wild bootstrap be performed in blocks, with # replications per block. The wild bootstrap
computation requires a matrix with dimensions (# groups) x (# replications). If this is too large, you can reduce the
matrix to (# groups) x (# block size) and loop (# replications)/(# block size) times. When the same random seed is set,
using a different block size does not change the numerical results; it only modifies the computation method. The block
size must be less than or equal to the number of bootstrap replications.
Outline
• The Question
• An Intuitive Introduction
• Two Period, Two Groups Model
• Repeated Cross-Sectional Panel Data
• Longitudinal Panel Data
• More information
DiD For Repeated Cross-Sectional Data
DiD For Repeated Cross-Sectional Data
Control Treatment
Group
FIPS 33 13
Time
Minimum 1970 1981
Maximum 1970 1981
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
ATET
TimeTreat
(1 vs 0) -3.268054 4.212866 -0.78 0.442 -11.7532 5.217093
Note: ATET estimate adjusted for group effects and time effects.
DiD For Repeated Cross-Sectional Data
estat trendplots
DiD For Repeated Cross-Sectional Data
. estat granger
Control Treatment
Group
FIPS 33 13
Time
Minimum 1970 1981
Maximum 1970 1981
Robust
mrate_agegrp Coefficient std. err. t P>|t| [95% conf. interval]
ATET
TimeTreat
(1 vs 0) -3.268054 4.134048 -0.79 0.433 -11.59445 5.058346
Note: ATET estimate adjusted for panel effects and time effects.
DiD For Longitudinal/Panel Data
estat trendplots
DiD For Longitudinal/Panel Data
. estat granger
didregress https://www.stata.com/manuals/te.pdf
xtdidregress https://www.stata.com/manuals/xt.pdf
More Information
More Information
Questions?