fect – User Manual

Welcome!

This Quarto book serves as a user manual for the fect package in R, which implements counterfactual (imputation) estimators for causal inference with panel data and performs diagnostic tests.

fect covers 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). This Quarto book also facilitates the application of various new difference-in-differences (DID) estimators. For details of these methods, see

  • Xu (2017) for Gsynth [Paper]

  • Liu, Wang, and Xu (2024) for counterfactual estimators [Paper]

  • Chiu et al. (2025) for a survey of the new DID estimators [Paper]

Source Code

For those interested in exploring the algorithms used in fect for calculating estimates, please visit the source GitHub Repo for further details.

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’Haultfœuille (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, and Spiess 2024).
  • 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. (2025) reanalyze 49 published studies in political science and offer 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 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:

Contributors

The following individuals have contributed to gsynth and fect, listed in the order of their involvement in the project:

Special thanks to Ziyi, Tianzhu, and Rivka for their tireless efforts in improving this package. Thanks to Jinwen for setting up and maintaining this User Manual.

Update Log

v2.1.0

(2025-10-27)

  • Fix speed issue
  • Rewrite complex fixed effect handling
  • Fixed various bugs

v2.0.5

(2025-08-25) CRAN release.

  • Fixed various bugs due to changes in dependencies
  • Added limit to cores by default in parallel computing
  • Add new plot type = "hte"
  • Added R-CMD-check for merging

v2.0.2

(2025-05-07)

  • Fixed various bugs
  • Updated counterfactual plot
  • Added sensitivity analysis
  • Added did_wrapper() and esplot()
  • Added various plotting options
  • Improved documentation

v2.0.0

(2025-01-17) CRAN release.

  • Changed to new syntax
  • Fixed various bugs
  • Added get_cohort()
  • Merged in gsynth

Report Bugs

Please report any bugs by submitting an issue on GitHub or emailing me (yiqingxu [at] stanford.edu). We’d really appreciate it if you can include your minimally replicable code & data file and a panelView treatment status plot. Your feedback is highly valued!

fect: Lifecycle: stable License: MIT CRAN status CRAN downloads

gsynth (retiring): License: MIT CRAN status downloads: CRAN