att_gt {did}  R Documentation 
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
)
yname 
The name of the outcome variable 
tname 
The name of the column containing the time periods 
idname 
The individual (crosssectional unit) id name 
gname 
The name of the variable in 
xformla 
A formula for the covariates to include in the
model. It should be of the form 
data 
The name of the data.frame that contains the data 
panel 
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 
allow_unbalanced_panel 
Whether or not function should
"balance" the panel with respect to time and id. The default
values if 
control_group 
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

anticipation 
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 
weightsname 
The name of the column containing the sampling weights. If not set, all observations have same weight. 
alp 
the significance level, default is 0.05 
bstrap 
Boolean for whether or not to compute standard errors using
the multiplier bootstrap. If standard errors are clustered, then one
must set 
cband 
Boolean for whether or not to compute a uniform confidence
band that covers all of the grouptime average treatment effects
with fixed probability 
biters 
The number of bootstrap iterations to use. The default is 1000,
and this is only applicable if 
clustervars 
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 
est_method 
the method to compute grouptime average treatment effects. The default is "dr" which uses the doubly robust
approach in the 
base_period 
Whether to use a "varying" base period or a "universal" base period. Either choice results in the same posttreatment estimates of ATT(g,t)'s. In pretreatment periods, using a varying base period amounts to computing a pseudoATT in each treatment period by comparing the change in outcomes for a particular group relative to its comparison group in the pretreatment periods (i.e., in pretreatment periods this setting computes changes from period t1 to period t, but repeatedly changes the value of t) A universal base period fixes the base period to always be (ganticipation1). This does not compute pseudoATT(g,t)'s in pretreatment periods, but rather reports average changes in outcomes from period t to (ganticipation1) 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. 
print_details 
Whether or not to show details/progress of computations.
Default is 
pl 
Whether or not to use parallel processing 
cores 
The number of cores to use for parallel processing 
an MP
object containing all the results for grouptime 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. "DifferenceinDifferences with Multiple Time Periods." Journal of Econometrics, Vol. 225, No. 2, pp. 200230, 2021. <https://doi.org/10.1016/j.jeconom.2020.12.001>, <https://arxiv.org/abs/1803.09015> #> #> GroupTime Average Treatment Effects: #> Group Time ATT(g,t) Std. Error [95% Simult. Conf. Band] #> 2004 2004 0.0105 0.0235 0.0752 0.0542 #> 2004 2005 0.0704 0.0307 0.1549 0.0140 #> 2004 2006 0.1373 0.0365 0.2379 0.0367 * #> 2004 2007 0.1008 0.0383 0.2062 0.0046 #> 2006 2004 0.0065 0.0236 0.0585 0.0715 #> 2006 2005 0.0028 0.0195 0.0564 0.0509 #> 2006 2006 0.0046 0.0185 0.0556 0.0464 #> 2006 2007 0.0412 0.0202 0.0969 0.0145 #> 2007 2004 0.0305 0.0155 0.0122 0.0733 #> 2007 2005 0.0027 0.0158 0.0462 0.0408 #> 2007 2006 0.0311 0.0176 0.0794 0.0173 #> 2007 2007 0.0261 0.0167 0.0720 0.0199 #>  #> Signif. codes: `*' confidence band does not cover 0 #> #> Pvalue for pretest 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. "DifferenceinDifferences with Multiple Time Periods." Journal of Econometrics, Vol. 225, No. 2, pp. 200230, 2021. <https://doi.org/10.1016/j.jeconom.2020.12.001>, <https://arxiv.org/abs/1803.09015> #> #> GroupTime Average Treatment Effects: #> Group Time ATT(g,t) Std. Error [95% Simult. Conf. Band] #> 2004 2004 0.0145 0.0233 0.0759 0.0469 #> 2004 2005 0.0764 0.0297 0.1546 0.0018 #> 2004 2006 0.1404 0.0348 0.2321 0.0488 * #> 2004 2007 0.1069 0.0340 0.1964 0.0174 * #> 2006 2004 0.0005 0.0236 0.0627 0.0618 #> 2006 2005 0.0062 0.0184 0.0548 0.0424 #> 2006 2006 0.0010 0.0194 0.0502 0.0521 #> 2006 2007 0.0413 0.0189 0.0912 0.0086 #> 2007 2004 0.0267 0.0145 0.0115 0.0650 #> 2007 2005 0.0046 0.0163 0.0476 0.0384 #> 2007 2006 0.0284 0.0191 0.0788 0.0219 #> 2007 2007 0.0288 0.0166 0.0724 0.0149 #>  #> Signif. codes: `*' confidence band does not cover 0 #> #> Pvalue for pretest 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. "DifferenceinDifferences with Multiple Time Periods." Journal of Econometrics, Vol. 225, No. 2, pp. 200230, 2021. <https://doi.org/10.1016/j.jeconom.2020.12.001>, <https://arxiv.org/abs/1803.09015> #> #> GroupTime Average Treatment Effects: #> Group Time ATT(g,t) Std. Error [95% Simult. Conf. Band] #> 2004 2004 0.0212 0.0225 0.0810 0.0386 #> 2004 2005 0.0816 0.0296 0.1603 0.0029 * #> 2004 2006 0.1382 0.0382 0.2397 0.0367 * #> 2004 2007 0.1069 0.0353 0.2007 0.0131 * #> 2006 2004 0.0075 0.0236 0.0703 0.0553 #> 2006 2005 0.0046 0.0193 0.0559 0.0468 #> 2006 2006 0.0087 0.0171 0.0367 0.0540 #> 2006 2007 0.0413 0.0195 0.0931 0.0105 #> 2007 2004 0.0269 0.0136 0.0093 0.0632 #> 2007 2005 0.0042 0.0158 0.0461 0.0377 #> 2007 2006 0.0284 0.0185 0.0777 0.0208 #> 2007 2007 0.0288 0.0167 0.0732 0.0156 #>  #> Signif. codes: `*' confidence band does not cover 0 #> #> Pvalue for pretest 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. \"DifferenceinDifferences with Multiple Time Periods.\" Journal of Econometrics, Vol. 225, No. 2, pp. 200230, 2021. doi:10.1016/j.jeconom.2020.12.001, https://arxiv.org/abs/1803.09015