Skip to content

Instantly share code, notes, and snippets.

@scunning1975
Created February 20, 2022 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scunning1975/bbb067f34d7cfd8421bfb827c2b744cf to your computer and use it in GitHub Desktop.
Save scunning1975/bbb067f34d7cfd8421bfb827c2b744cf to your computer and use it in GitHub Desktop.
R code for Sun and Abraham
# Sun and Abraham (SA20)
unique(baker$treat_date)
# This time, our SA implementation is a little different because we don't have a
# "never treated" group. (Everyone get's treated eventually.) So, we'll use our
# last treated cohort (i.e. 2004) as the control group. In practice this means
# that we have to subset our data by dropping all observations after this final
# treatment year. You could create a new dataset, but here we'll just use the
# `subset` argument to drop these observations on the fly.
res_cohort = feols(y ~ sunab(treat_date, year) | id + year,
baker, subset = ~year<2004, ## NB: subset!
vcov = ~state)
summary(res_cohort)
iplot(res_cohort, ref.line = -1, main = "Sun & Abraham")
# Can also use iplot to plot them together
iplot(list(res_naive, res_cohort), ref.line = -1,
main = "Treatment's effect on y")
legend("topright", col = c(1, 2), pch = c(20, 17),
legend = c("TWFE", "Sun & Abraham"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment