att_gt
computes average treatment effects in DID
setups where there are more than two periods of data and allowing for
treatment to occur at different points in time and allowing for
treatment effect heterogeneity and dynamics.
See Callaway and Sant'Anna (2021) for a detailed description.
att_gt(
yname,
tname,
idname = NULL,
gname,
xformla = NULL,
data,
panel = TRUE,
allow_unbalanced_panel = FALSE,
control_group = c("nevertreated", "notyettreated"),
anticipation = 0,
weightsname = NULL,
alp = 0.05,
bstrap = TRUE,
cband = TRUE,
biters = 1000,
clustervars = NULL,
est_method = "dr",
base_period = "varying",
print_details = FALSE,
pl = FALSE,
cores = 1
)
The name of the outcome variable
The name of the column containing the time periods
The individual (cross-sectional unit) id name
The name of the variable in data
that
contains the first period when a particular observation is treated.
This should be a positive number for all observations in treated groups.
It defines which "group" a unit belongs to. It should be 0 for units
in the untreated group.
A formula for the covariates to include in the
model. It should be of the form ~ X1 + X2
. Default
is NULL which is equivalent to xformla=~1
. This is
used to create a matrix of covariates which is then passed
to the 2x2 DID estimator chosen in est_method
.
The name of the data.frame that contains the data
Whether or not the data is a panel dataset.
The panel dataset should be provided in long format – that
is, where each row corresponds to a unit observed at a
particular point in time. The default is TRUE. When
is using a panel dataset, the variable idname
must
be set. When panel=FALSE
, the data is treated
as repeated cross sections.
Whether or not function should
"balance" the panel with respect to time and id. The default
values if FALSE
which means that att_gt()
will drop
all units where data is not observed in all periods.
The advantage of this is that the computations are faster
(sometimes substantially).
Which units to use the control group.
The default is "nevertreated" which sets the control group
to be the group of units that never participate in the
treatment. This group does not change across groups or
time periods. The other option is to set
group="notyettreated"
. In this case, the control group
is set to the group of units that have not yet participated
in the treatment in that time period. This includes all
never treated units, but it includes additional units that
eventually participate in the treatment, but have not
participated yet.
The number of time periods before participating in the treatment where units can anticipate participating in the treatment and therefore it can affect their untreated potential outcomes
The name of the column containing the sampling weights. If not set, all observations have same weight.
the significance level, default is 0.05
Boolean for whether or not to compute standard errors using
the multiplier bootstrap. If standard errors are clustered, then one
must set bstrap=TRUE
. Default is TRUE
(in addition, cband
is also by default TRUE
indicating that uniform confidence bands
will be returned. If bstrap is FALSE
, then analytical
standard errors are reported.
Boolean for whether or not to compute a uniform confidence
band that covers all of the group-time average treatment effects
with fixed probability 1-alp
. In order to compute uniform confidence
bands, bstrap
must also be set to TRUE
. The default is
TRUE
.
The number of bootstrap iterations to use. The default is 1000,
and this is only applicable if bstrap=TRUE
.
A vector of variables names to cluster on. At most, there
can be two variables (otherwise will throw an error) and one of these
must be the same as idname which allows for clustering at the individual
level. By default, we cluster at individual level (when bstrap=TRUE
).
the method to compute group-time average treatment effects. The default is "dr" which uses the doubly robust
approach in the DRDID
package. Other built-in methods
include "ipw" for inverse probability weighting and "reg" for
first step regression estimators. The user can also pass their
own function for estimating group time average treatment
effects. This should be a function
f(Y1,Y0,treat,covariates)
where Y1
is an
n
x 1
vector of outcomes in the post-treatment
outcomes, Y0
is an n
x 1
vector of
pre-treatment outcomes, treat
is a vector indicating
whether or not an individual participates in the treatment,
and covariates
is an n
x k
matrix of
covariates. The function should return a list that includes
ATT
(an estimated average treatment effect), and
inf.func
(an n
x 1
influence function).
The function can return other things as well, but these are
the only two that are required. est_method
is only used
if covariates are included.
Whether to use a "varying" base period or a "universal" base period. Either choice results in the same post-treatment estimates of ATT(g,t)'s. In pre-treatment periods, using a varying base period amounts to computing a pseudo-ATT in each treatment period by comparing the change in outcomes for a particular group relative to its comparison group in the pre-treatment periods (i.e., in pre-treatment periods this setting computes changes from period t-1 to period t, but repeatedly changes the value of t)
A universal base period fixes the base period to always be (g-anticipation-1). This does not compute pseudo-ATT(g,t)'s in pre-treatment periods, but rather reports average changes in outcomes from period t to (g-anticipation-1) for a particular group relative to its comparison group. This is analogous to what is often reported in event study regressions.
Using a varying base period results in an estimate of ATT(g,t) being reported in the period immediately before treatment. Using a universal base period normalizes the estimate in the period right before treatment (or earlier when the user allows for anticipation) to be equal to 0, but one extra estimate in an earlier period.
Whether or not to show details/progress of computations.
Default is FALSE
.
Whether or not to use parallel processing
The number of cores to use for parallel processing
an MP
object containing all the results for group-time average
treatment effects
Basic att_gt()
call:
# Example data
data(mpdta)
out1 <- att_gt(yname="lemp",
tname="year",
idname="countyreal",
gname="first.treat",
xformla=NULL,
data=mpdta)
summary(out1)
#>
#> Call:
#> att_gt(yname = "lemp", tname = "year", idname = "countyreal",
#> gname = "first.treat", xformla = NULL, data = mpdta)
#>
#> Reference: Callaway, Brantly and Pedro H.C. Sant'Anna. "Difference-in-Differences with Multiple Time Periods." Journal of Econometrics, Vol. 225, No. 2, pp. 200-230, 2021. <https://doi.org/10.1016/j.jeconom.2020.12.001>, <https://arxiv.org/abs/1803.09015>
#>
#> Group-Time Average Treatment Effects:
#> Group Time ATT(g,t) Std. Error [95% Simult. Conf. Band]
#> 2004 2004 -0.0105 0.0249 -0.0772 0.0562
#> 2004 2005 -0.0704 0.0320 -0.1560 0.0152
#> 2004 2006 -0.1373 0.0392 -0.2421 -0.0324 *
#> 2004 2007 -0.1008 0.0363 -0.1980 -0.0037 *
#> 2006 2004 0.0065 0.0233 -0.0560 0.0690
#> 2006 2005 -0.0028 0.0186 -0.0526 0.0471
#> 2006 2006 -0.0046 0.0176 -0.0517 0.0425
#> 2006 2007 -0.0412 0.0194 -0.0931 0.0106
#> 2007 2004 0.0305 0.0149 -0.0095 0.0705
#> 2007 2005 -0.0027 0.0162 -0.0460 0.0405
#> 2007 2006 -0.0311 0.0174 -0.0777 0.0156
#> 2007 2007 -0.0261 0.0163 -0.0698 0.0177
#> ---
#> Signif. codes: `*' confidence band does not cover 0
#>
#> P-value for pre-test of parallel trends assumption: 0.16812
#> Control Group: Never Treated, Anticipation Periods: 0
#> Estimation Method: Doubly Robust
Using covariates:
out2 <- att_gt(yname="lemp",
tname="year",
idname="countyreal",
gname="first.treat",
xformla=~lpop,
data=mpdta)
summary(out2)
#>
#> Call:
#> att_gt(yname = "lemp", tname = "year", idname = "countyreal",
#> gname = "first.treat", xformla = ~lpop, data = mpdta)
#>
#> Reference: Callaway, Brantly and Pedro H.C. Sant'Anna. "Difference-in-Differences with Multiple Time Periods." Journal of Econometrics, Vol. 225, No. 2, pp. 200-230, 2021. <https://doi.org/10.1016/j.jeconom.2020.12.001>, <https://arxiv.org/abs/1803.09015>
#>
#> Group-Time Average Treatment Effects:
#> Group Time ATT(g,t) Std. Error [95% Simult. Conf. Band]
#> 2004 2004 -0.0145 0.0224 -0.0749 0.0458
#> 2004 2005 -0.0764 0.0300 -0.1573 0.0045
#> 2004 2006 -0.1404 0.0363 -0.2385 -0.0424 *
#> 2004 2007 -0.1069 0.0340 -0.1988 -0.0150 *
#> 2006 2004 -0.0005 0.0231 -0.0629 0.0619
#> 2006 2005 -0.0062 0.0189 -0.0572 0.0448
#> 2006 2006 0.0010 0.0205 -0.0542 0.0562
#> 2006 2007 -0.0413 0.0195 -0.0939 0.0114
#> 2007 2004 0.0267 0.0145 -0.0125 0.0659
#> 2007 2005 -0.0046 0.0165 -0.0491 0.0400
#> 2007 2006 -0.0284 0.0186 -0.0786 0.0217
#> 2007 2007 -0.0288 0.0154 -0.0704 0.0129
#> ---
#> Signif. codes: `*' confidence band does not cover 0
#>
#> P-value for pre-test of parallel trends assumption: 0.23267
#> Control Group: Never Treated, Anticipation Periods: 0
#> Estimation Method: Doubly Robust
Specify comparison units:
out3 <- att_gt(yname="lemp",
tname="year",
idname="countyreal",
gname="first.treat",
xformla=~lpop,
control_group = "notyettreated",
data=mpdta)
summary(out3)
#>
#> Call:
#> att_gt(yname = "lemp", tname = "year", idname = "countyreal",
#> gname = "first.treat", xformla = ~lpop, data = mpdta, control_group = "notyettreated")
#>
#> Reference: Callaway, Brantly and Pedro H.C. Sant'Anna. "Difference-in-Differences with Multiple Time Periods." Journal of Econometrics, Vol. 225, No. 2, pp. 200-230, 2021. <https://doi.org/10.1016/j.jeconom.2020.12.001>, <https://arxiv.org/abs/1803.09015>
#>
#> Group-Time Average Treatment Effects:
#> Group Time ATT(g,t) Std. Error [95% Simult. Conf. Band]
#> 2004 2004 -0.0212 0.0238 -0.0845 0.0422
#> 2004 2005 -0.0816 0.0304 -0.1625 -0.0007 *
#> 2004 2006 -0.1382 0.0379 -0.2391 -0.0373 *
#> 2004 2007 -0.1069 0.0343 -0.1982 -0.0156 *
#> 2006 2004 -0.0075 0.0219 -0.0656 0.0507
#> 2006 2005 -0.0046 0.0199 -0.0575 0.0484
#> 2006 2006 0.0087 0.0165 -0.0351 0.0524
#> 2006 2007 -0.0413 0.0197 -0.0937 0.0111
#> 2007 2004 0.0269 0.0136 -0.0092 0.0630
#> 2007 2005 -0.0042 0.0156 -0.0456 0.0372
#> 2007 2006 -0.0284 0.0185 -0.0776 0.0207
#> 2007 2007 -0.0288 0.0154 -0.0697 0.0121
#> ---
#> Signif. codes: `*' confidence band does not cover 0
#>
#> P-value for pre-test of parallel trends assumption: 0.23326
#> Control Group: Not Yet Treated, Anticipation Periods: 0
#> Estimation Method: Doubly Robust
Callaway, Brantly and Pedro H.C. Sant'Anna. \"Difference-in-Differences with Multiple Time Periods.\" Journal of Econometrics, Vol. 225, No. 2, pp. 200-230, 2021. doi:10.1016/j.jeconom.2020.12.001 , https://arxiv.org/abs/1803.09015