This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulation study for the Medium article: | |
# Event Studies for Causal Inference: The Dos and Don'ts - | |
# A guide to avoiding the common pitfalls of event studies | |
# This code simulates a panel dataset and then runs event studies | |
# Different scenarios are created to demonstrate pitfalls of event studies | |
# The simulaiton part of the code is adapted from Andrew Baker's awesome blog: | |
# https://andrewcbaker.netlify.app/2020/06/27/how-to-create-relative-time-indicators/ | |
# Also see a relevant package and blog by Sant'Anna & Callaway: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulate the data | |
# The simulaiton part of the code is adapted from Andrew Baker's awesome blog: | |
# https://andrewcbaker.netlify.app/2020/06/27/how-to-create-relative-time-indicators/ | |
# Also see a relevant package and blog by Sant'Anna & Callaway: | |
# https://bcallaway11.github.io/did/articles/pre-testing.html | |
rm(list = ls()) | |
library(data.table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulation study for the DiD article: | |
rm(list = ls()) | |
library(data.table) | |
library(fastDummies) # Create dummy variables | |
library(fixest) # Fixed-effects regression | |
library(kableExtra) # Make nice tables | |
library(bacondecomp) # Goodman-Bacon Decomposition | |
library(did) # Difference-in-differences |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install and load the required packages | |
# devtools::install_github("synth-inference/synthdid") | |
library(synthdid) | |
library(ggplot2) | |
library(fixest) # Fixed-effects regression | |
library(data.table) | |
# Set seed for reproducibility | |
set.seed(12345) |