Statistical Packages in R and Stata
Name: PCDID - Principal Components Difference-in-Differences
Title line: Factor-augmented difference-in-differences estimation when trends may be unparallel and/or stochastic
Description: pcdid executes a principal components difference-in-differences regression based on Chan and Kwok (2016, 2020). It is useful in situations where the user suspects that trends may be unparallel and/or stochastic among control and treated units. The data structure is the same as that in a DID setup. The estimation method is regression-based and can be considered as an extension of conventional DID regressions. The command also implements a parallel trend alpha test (based on an interactive effects structure) and a recursive procedure that determines the number of factors automatically.
R module:
https://cran.r-project.org/web/packages/pcdid/index.html
https://github.com/adamwang15/pcdid
Reference manual: pcdid.html , pcdid.pdf
To install the package, type "install.packages("pcdid")" in R Studio. The package contains an example dataset called "welfare". Run the following code on the example data.
library(pcdid)
result <- pcdid(
lncase ~ treated + treated_post + afdcben + unemp + empratio + mon_d2 + mon_d3 + mon_d4,
index = c("state", "trend"),
data = welfare,
alpha = TRUE
)
Stata module:
STATA ado file1 STATA ado file2 STATA ado file3
Version 1.01. To install the package, type "ssc install pcdid" in STATA.
(Alternatively, copy the above ado and help files to your personal ado directory. This directory can be found by typing "personal" in STATA. (Typically it is c:\ado\personal\ on a windows machine.)
Reference: The PCDID Approach: Difference-in-Differences when Trends are Potentially Unparallel and Stochastic (with Simon Kwok) JBES 2022
Online Appendix
Please click on a link below: