11
11
# ' @param xformla A formula for the covariates to include in the model.
12
12
# ' It should be of the form `~ X1 + X2`. Default is NULL.
13
13
# ' @param weights Variable name for estimation weights. This is used in
14
- # ' estimating Y(0) and also augments treatment effect weights
14
+ # ' estimating Y(0) and also augments treatment effect weights.
15
+ # ' Implementation of Roth and Sant'Anna (2021) currently does not allow for weights.
15
16
# ' @param estimator Estimator you would like to use. Use "all" to estimate all.
16
17
# ' Otherwise see table to know advantages and requirements for each of these.
17
18
# '
@@ -67,6 +68,11 @@ event_study = function(data, yname, idname, gname, tname,
67
68
message(paste0(" Warning: `" , xformla , " ` is ignored for the `staggered` estimator" ))
68
69
}
69
70
}
71
+
72
+ # Checking weights
73
+ if (! (is.null(weights ) || is.character(weights ))) {
74
+ stop(" Argument `weights` must be `NULL` or a character string" )
75
+ }
70
76
71
77
# Setup ------------------------------------------------------------------------
72
78
@@ -114,7 +120,15 @@ if(estimator %in% c("TWFE", "all")) {
114
120
yname , " ~ 1 + " , xformla_null , " + i(zz000event_time, ref = c(-1, -Inf)) | " , idname , " + " , tname
115
121
)
116
122
)
117
- est_twfe = fixest :: feols(twfe_formula , data = data , warn = F , notes = F )
123
+ if (is.null(weights )){
124
+ est_twfe = fixest :: feols(twfe_formula , data = data ,
125
+ warn = F , notes = F )
126
+ } else {
127
+ est_twfe = fixest :: feols(twfe_formula , data = data ,
128
+ weights = as.matrix(data [weights ]),
129
+ warn = F , notes = F )
130
+ }
131
+
118
132
119
133
# Extract coefficients and standard errors
120
134
tidy_twfe = broom :: tidy(est_twfe )
@@ -143,7 +157,7 @@ if(estimator %in% c("did2s", "all")) {
143
157
)
144
158
)
145
159
146
- est_did2s = did2s :: did2s(data , yname = yname , first_stage = did2s_first_stage , second_stage = ~ i(zz000event_time , ref = - Inf ), treatment = " zz000treat" , cluster_var = idname , verbose = FALSE )
160
+ est_did2s = did2s :: did2s(data , yname = yname , first_stage = did2s_first_stage , second_stage = ~ i(zz000event_time , ref = - Inf ), treatment = " zz000treat" , cluster_var = idname , weights = weights , verbose = FALSE )
147
161
148
162
# Extract coefficients and standard errors
149
163
tidy_did2s = broom :: tidy(est_did2s )
@@ -166,7 +180,10 @@ if(estimator %in% c("did", "all")) {
166
180
message(" Estimating using Callaway and Sant'Anna (2020)" )
167
181
168
182
try({
169
- est_did = did :: att_gt(yname = yname , tname = tname , idname = idname , gname = gname , xformla = xformla , data = data )
183
+ est_did = did :: att_gt(yname = yname , tname = tname , idname = idname ,
184
+ gname = gname , xformla = xformla ,
185
+ data = data , weightsname = weights ,
186
+ allow_unbalanced_panel = FALSE )
170
187
171
188
est_did = did :: aggte(est_did , type = " dynamic" , na.rm = TRUE )
172
189
@@ -198,8 +215,11 @@ if(estimator %in% c("sunab", "all")) {
198
215
yname , " ~ " , sunab_xformla , " + sunab(" , gname , " , zz000event_time, ref.c =0, ref.p = -1) | " , idname , " + " , tname
199
216
)
200
217
)
201
-
202
- est_sunab = fixest :: feols(sunab_formla , data = data )
218
+ if (is.null(weights )){
219
+ est_sunab = fixest :: feols(sunab_formla , data = data )
220
+ } else {
221
+ est_sunab = fixest :: feols(sunab_formla , data = data , weights = as.matrix(data [weights ]))
222
+ }
203
223
204
224
tidy_sunab = broom :: tidy(est_sunab )
205
225
@@ -228,7 +248,7 @@ if(estimator %in% c("impute", "all")) {
228
248
)
229
249
230
250
tidy_impute = didimputation :: did_imputation(data ,
231
- yname = yname , gname = gname , tname = tname , idname = idname ,
251
+ yname = yname , gname = gname , tname = tname , idname = idname , wname = weights ,
232
252
first_stage = impute_first_stage , horizon = TRUE , pretrends = TRUE )
233
253
234
254
# Subset columns
@@ -275,6 +295,7 @@ if(estimator %in% c("staggered", "all")) {
275
295
})
276
296
277
297
if (is.null(tidy_staggered )) warning(" Roth and Sant'Anna (2021) Failed" )
298
+ if (! is.null(weights )) warning(" Roth and Sant'Anna (2021) Does Not Allow Weights" )
278
299
}
279
300
280
301
# Bind results together --------------------------------------------------------
0 commit comments