knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
This R package implements the multi-period diff-diff as discussed in Imai and Kim (2019) and Chaisemartin and Hautfeuille (2019).
devtools::install_github("MatthieuStigler/multiDiff")
DD()
: period-by-period diff-diff (DiD)DD_manu()
: DiD the manual way: showing the four meansDD_manu_many()
: period-by-period manual DiDFE_decompo()
: FE decomposition following Gibbons et al mDid_weights_CH()
: Weights from Chaisemartin and Hautefeuille (2020)Main function is DD()
(name might change!), with following arguments
y_var
The name of the y variabletreat treatment
The name of the treatment variabletime.index
The name of the time dimension variableunit.index
The name of the unit dimension variabledata
The datasetlibrary(multiDiff) suppressMessages(library(tidyverse)) data <- sim_dat(N=100) DD_out <- DD(data=data) ## Main output is: knitr::kable(DD_out[1:5,])
Plot the year-by-year treatment:
DD_out %>% filter(DiD %in% c(1,4)) %>% mutate(case = paste("Treat: ", treat, ", Control: ", control, sep = "")) %>% ggplot(aes(x=time, y = estimate, color = case)) + geom_ribbon(aes(ymin = .data$conf.low, ymax = .data$conf.high, group = case), fill = "grey", alpha = I(0.4), linetype = 2) + geom_line(size = 1) + theme(legend.position = "bottom") + geom_hline(yintercept =1, linetype = 2) + ggtitle("Diff-diff by year and identification case")
Aggregate the results over time:
DiD_aggreg(x=DD_out, by_DiD = FALSE) DiD_aggreg(x=DD_out, by_DiD = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.