knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
bacondecomp
is a package with tools to perform the Goodman-Bacon decomposition for differences-in-differences with variation in treatment timing. The decomposition can be done with and without time-varying covariates.
You can install bacondecomp 0.1.1
from CRAN:
install.packages("bacondecomp")
You can install the development version of bacondecomp
from GitHub:
library(devtools) install_github("evanjflack/bacondecomp")
bacon()
: calculates all 2x2 differences-in-differences estimates and weights for the Bacon-Goodman decomposition.math_refom
: Aggregated data from Goodman (2019, JOLE)castle
: Data from Cheng and Hoekstra (2013, JHR)divorce:
Data from Stevenson and Wolfers (2006, QJE)This is a basic example which shows you how to use the bacon() function to decompose the two-way fixed effects estimate of the effect of an education reform on future earnings following Goodman (2019, JOLE).
library(bacondecomp) df_bacon <- bacon(incearn_ln ~ reform_math, data = bacondecomp::math_reform, id_var = "state", time_var = "class") # All 2x2 Comparisons head(df_bacon) # Summary of Early vs. Later, Later vs. Earlier, and Treated vs. Untreated bacon_summary(df_bacon)
library(ggplot2) ggplot(df_bacon) + aes(x = weight, y = estimate, shape = factor(type)) + geom_point() + geom_hline(yintercept = 0) + theme_minimal() + labs(x = "Weight", y = "Estimate", shape = "Type")
Goodman-Bacon, Andrew. 2018. "Difference-in-Differences with Variation in Treatment Timing." National Bureau of Economic Research Working Paper Series No. 25018. doi: 10.3386/w25018.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.