knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
r badger::badge_devel("CdfInnovLab/didImputation", "blue")
r badger::badge_code_size("CdfInnovLab/didImputation")
Estimation of staggered Difference-in-Differences using the imputation approach of Borusyak, Jaravel, and Spiess (2021). The packages allows for:
Multiple time periods
Staggered design (i.e., units are treated at different time periods)
Continuous controls
The package implements an imputation method to estimate the treatment effect and pre-trend testing in difference-in-differences designs with staggered adoption (i.e where units are treated at different time periods). Recent literature stress out the importance of not using the standard twoway fixed effect regression.
The standard DiD setup involves two periods and two groups (one treated and one untreated), it relies on parallel trend assumption to estimate the treatment effect of the treated. The staggered DiD setup is the generalization of this approach to multiple periods and multiple groups (i.e. individuals treated at different time periods.). Recent literature stress out the need to not use the standard two-way fixed effect (TWFE) regression to estimate those models. This package implements a method of imputation to estimate the average treatment effect. The package uses untreated observations to predict the counterfactual outcome on treated observations and provide the appropriate Standard errors. It provides ways to test for parallel trends.
You can install the github version with devtools
or renv
(recommended, read more about renv)
devtools::install("CdfInnovLab/didImputation")
library(didImputation)
data(did_simulated) res <- didImputation(y0 = y ~ 0 | i + t, cohort = 'g', data = did_simulated) summary(res)
You can print the result easily with didplot
didplot(res)
didImputation estimates the effects of a binary treatment with staggered timing. It allows for arbitrary heterogeneity of treatment and dynamic effects.
The estimation is a three step procedures
Impute the treated observations ($it \in \Omega_1$) potential outcome $Y_{it}(0)$ and obtain treatment effect $\tau_{it}$ by substracting the predicted outcome from step 1 $$\begin{align} \hat{Y}{it}(0|it \in \Omega_1) &= \hat{\alpha}_i + \hat{\beta}_t + X{it}'\hat{\delta} \ \hat{\tau}{it} &= Y{it} - \hat{Y}_{it}(0) \end{align}$$
Average estimated treatment effects $\tau_{it}$ to the estimand of interest.
For the overall average treatment effect, the estimate is defined by $$\hat{\tau} = \sum_{it \in \Omega_1} \tau_{it}$$
didimputation: Another implementation using sparse matrix inversion.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.