View source: R/did_imputation.R
did_imputation | R Documentation |
Treatment effect estimation and pre-trend testing in staggered adoption diff-in-diff designs with an imputation approach of Borusyak, Jaravel, and Spiess (2021)
did_imputation( data, yname, gname, tname, idname, first_stage = NULL, wname = NULL, wtr = NULL, horizon = NULL, pretrends = NULL, cluster_var = NULL )
data |
A |
yname |
String. Variable name for outcome. Use |
gname |
String. Variable name for unit-specific date of treatment
(never-treated should be zero or |
tname |
String. Variable name for calendar period. |
idname |
String. Variable name for unique unit id. |
first_stage |
Formula for Y(0).
Formula following |
wname |
String. Variable name for estimation weights of observations. This is used in estimating Y(0) and also augments treatment effect weights. |
wtr |
Character vector of treatment weight names (see horizon for standard static and event-study weights) |
horizon |
Integer vector of event_time or |
pretrends |
Integer vector or |
cluster_var |
String. Varaible name for clustering groups. If not
supplied, then |
The imputation-based estimator is a method of calculating treatment effects in a difference-in-differences framework. The method estimates a model for Y(0) using untreated/not-yet-treated observations and predicts Y(0) for the treated observations hat(Y_it(0)). The difference between treated and predicted untreated outcomes Y_it(1) - hat(Y_it(0)) serves as an estimate for the treatment effect for unit i in period t. These are then averaged to form average treatment effects for groups of it.
A data.frame
containing treatment effect term, estimate, standard
error and confidence interval. This is in tidy
format.
Load example dataset which has two treatment groups and homogeneous treatment effects
# Load Example Dataset data("df_hom", package="did2s")
You can run a static TWFE fixed effect model for a simple treatment indicator
did_imputation(data = df_hom, yname = "dep_var", gname = "g", tname = "year", idname = "unit") #> # A tibble: 1 x 6 #> lhs term estimate std.error conf.low conf.high #> <chr> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 dep_var treat 2.00 0.0182 1.97 2.04
Or you can use relative-treatment indicators to estimate an event study estimate
did_imputation(data = df_hom, yname = "dep_var", gname = "g", tname = "year", idname = "unit", horizon=TRUE) #> # A tibble: 21 x 6 #> lhs term estimate std.error conf.low conf.high #> <chr> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 dep_var 0 1.97 0.0425 1.89 2.05 #> 2 dep_var 1 2.05 0.0434 1.97 2.14 #> 3 dep_var 2 2.03 0.0432 1.95 2.12 #> 4 dep_var 3 1.97 0.0428 1.88 2.05 #> 5 dep_var 4 1.97 0.0420 1.88 2.05 #> 6 dep_var 5 2.03 0.0423 1.95 2.11 #> 7 dep_var 6 2.04 0.0450 1.95 2.13 #> 8 dep_var 7 2.00 0.0437 1.91 2.08 #> 9 dep_var 8 2.02 0.0440 1.93 2.10 #> 10 dep_var 9 1.96 0.0440 1.87 2.04 #> # ... with 11 more rows
Here's an example using data from Cheng and Hoekstra (2013)
# Castle Data castle <- haven::read_dta("https://github.com/scunning1975/mixtape/raw/master/castle.dta") did_imputation(data = castle, yname = "c(l_homicide, l_assault)", gname = "effyear", first_stage = ~ 0 | sid + year, tname = "year", idname = "sid") #> # A tibble: 2 x 6 #> lhs term estimate std.error conf.low conf.high #> <chr> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 l_homicide treat 0.0798 0.0609 -0.0395 0.199 #> 2 l_assault treat 0.0496 0.0513 -0.0510 0.150
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.