knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

multiDiff

Lifecycle: experimental

This R package implements the multi-period diff-diff as discussed in Imai and Kim (2019) and Chaisemartin and Hautfeuille (2019).

Installation

devtools::install_github("MatthieuStigler/multiDiff")

Main functions:

Example

Main function is DD() (name might change!), with following arguments

library(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)


MatthieuStigler/multiDiff documentation built on Aug. 10, 2021, 9:42 p.m.