fect – User Manual
Welcome!
This Quarto Book serves as a user manual for the fect package in R, which is designed to implement counterfactual estimators (also known as imputation estimators) for causal inference with panel data and to perform diagnostic tests. For details on the methods, see Xu (2017) and Liu, Wang & Xu (2022).
fect introduces a series of counterfactual estimators, including the five estimators from the last version and integrating the latest version of the gsynth package for the generalized synthetic control method (Gsynth).
For those interested in exploring the algorithms used in fect for calculating estimates, please visit the source GitHub Repo for further details. R code used in the Quarto Book can be downloaded from here.
Why Counterfactual Estimators?
There are several reasons why you might consider using counterfactual estimators for your panel data applications:
- Because “causal inference is a missing data problem” (Holland 1986), it is natural to impute treated counterfactuals when the ATT, if well defined, is the primary quantity of interest.
- Counterfactual estimators help avoid the (negative) weighting problem, which has been highlighted in recent applied econometrics literature regarding TWFE models (e.g., Chaisemartin and d’Haultfoeuille, 2020; Goodman-Bacon, 2021).
- Among the newer estimators that accommodate heterogeneous treatment effects, the fixed effect counterfactual estimator (imputation based on TWFE) is the most efficient under homoskedasticity (Borusyak, Jaravel, & Spiess, 2021).
- Counterfactual estimators enable the use of more complex modeling strategies, such as linear factor models and matrix completion methods, which naturally connect to the synthetic control setting.
However, these counterfactual estimators come with important limitations:
- Most rely on some form of the parallel trends assumption or a low-rank structure.
- They generally do not accommodate dynamic treatment assignment based on sequential ignorability.
- Methods for continuous treatments are still underdeveloped and are not currently covered by fect.
Chiu et al. (2024) reanalyze numerous published studies in political science and offer detailed justifications for adopting these estimators.
Why the Merge?
I have decided to merge the two packages, gsynth and fect, as gsynth is fundamentally a counterfactual estimator. The two packages increasingly share similar code modules and features, including core algorithms (the ife
and mc
methods in both packages are essentially identical), tuning methods, and visualization tools. This merge will greatly simplify package maintenance moving forward.
However, some key differences between the two approaches remain:
- Gsynth is specifically designed for block and staggered DID settings without treatment reversal, while other methods accommodate treatment reversal under the assumption of limited carryover effects.
- Gsynth is particularly suited for cases where the number of treated units is small, including scenarios with only one treated unit. By setting
vartype = "parametric"
, we can use a two-stage parametric bootstrapping procedure—analogous to conformal inference—to produce uncertainty estimates. In contrast, other methods rely on large samples, particularly a large number of treated units, to obtain reliable standard errors and confidence intervals using"bootstrap"
or"jackknife"
. - Compared with IFEct (
method = "ife"
), Gsynth does not rely on pre-treatment data from the treated units to impute \(\hat{Y}(0)\). This approach significantly speeds up computation and improves stability.
Therefore, we recommend setting method = "gsynth"
in fect for scenarios where the treatment does not reverse (or is coded accordingly) and the number of treated units is small .
Moving forward, I will discontinue maintaining gsynth and focus on adding more functionalities to fect.
Organization
The user guide is structured into the following chapters:
Chapter 1 Get Started
This chapter covers installation instructions and introduces the datasets.Chapter 2 Fect Main Program
Here, we eplain how to apply the five estimators and diagnostic tests available in previous versions of fect, incorporating minor revisions to enhance clarity and demonstration.Chapter 3 Gsynth Program
This chapter provides a step-by-step guide to implementing all the functionalities of the original gsynth R package using fect.Chapter 4 Cheatsheet
The final chapter summarizes the core inputs required for implementing the six methods, along with options for plotting and diagnostics.
Contributors
The following individuals have contributed to gsynth and fect, listed in the order of their involvement in the project:
- Yiqing Xu
- Licheng Liu
- Ye Wang
- Ziyi Liu (PhD Student at Berkeley Haas)
- Shijian Liu (PhD Student at NYU Stern)
- Tianzhu Qin
- Jinwen Wu (Predoc at Stanford PoliSci)
Special thanks to Ziyi for his tireless efforts in improving this package. Thanks to Jinwen for setting up and maintaining this User Manual.
Report bugs
Please report any bugs to me (yiqingxu [at] stanford.edu) or submit an issue on GitHub. Please include your minimally replicable code & data file and a panelView treatment status plot. Your feedback is highly valued!