Yiqing Xu

Software

AI tools

Certify
Certify
Software for replication certification (beta) — it adds a signed, timestamped certificate to a replication dataset in Dataverse, so a journal or reader can check it in seconds without rerunning the analysis.
site / paper
ReproAI
ReproAI
An AI assistant for reproducible replication packages — it flags what a reproducibility check would catch, before you submit.
site / paper / GitHub
StatsClaw
StatsClaw
A multi-agent, AI-collaborative workflow for building, testing, translating, and maintaining statistical software — R, Python, C++, Julia, and Stata.
site / paper / GitHub

Panel data methods

fdid
fdid: Factorial Difference-in-Differences

fdid implements factorial difference-in-differences, a common research design that extends canonical difference-in-differences (DID) to settings in which an event affects all units.

R / Paper
bpCausal
bpCausal: Bayesian Causal Panel Analysis

bpCausal implements dynamic multilevel linear factor models (DM-LFMs), which are a Bayesian alternative to the synthetic control method for comparative case studies. It provides interpretable uncertainty estimates based on the Bayesian posterior distributions of the counterfactuals.

R / Paper
fect
fect: Fixed Effect Counterfactual Estimators

fect implements a group of counterfactual estimators for causal inference using panel data with binary treatments, including interactive fixed effects and matrix completion methods. It also offers several diagnostic tests, such as a placebo test (for no pre-trends).

R / Stata / Python / Paper / Slides
tjbal
tjbal: Trajectory Balancing

Using panel data with binary treatments, tjbal seeks balance on kernelized features from pretreatment periods, thus allowing users to draw causal inference on average and distributional effects under weak functional form assumptions.

R / Paper
gsynth
gsynth: Generalized Synthetic Control Method

gsynth implements the generalized synthetic control method, an imputation-based causal inference method for panel data with binary treatments following staggered adoption. The original gsynth package is retiring. All functionalities have been incorporated into fect.

R / R (wrapper) / Stata (fect) / Paper
panelView
panelView: Visualizing Panel Data

panelView provides four functions: (1) visualize treatment and missingness in panel data; (2) plot variables over time; (3) show bivariate relationships by unit or in aggregate; (4) display multi-way fixed effects as a k-partite graph, identifying components, singletons, and duplicates.

R / Stata / Paper

Choosing a panel method

Over the past few years, I have written three articles reviewing recent developments in causal panel analysis. I recommend interested readers review these before applying the methods on this page.

  1. Causal Inference with Time-Series Cross-Sectional Data: A Reflection: a discussion of two types of identification strategies for causal panel analysis
  2. A Practical Guide to Counterfactual Estimators for Causal Inference with Time-Series Cross-Sectional Data: a framework of counterfactual estimators for causal panel analysis
  3. Causal Panel Analysis under Parallel Trends: Lessons from a Large Reanalysis Study: a survey of recent DID methods and reanalysis of political science studies

With collaborators, I develop statistical routines for panel data visualization and analyses and for other causal inference and social data description purposes. Below are the use cases for the various panel methods:

  1. panelView: panel data visualization.
  2. gsynth: panel causal inference with binary treatments following staggered adoption. Suitable when the number of treated units is small. Requires a large number of pretreatment periods for each treated unit and a sizable never-treated group.
  3. fect: panel causal inference with binary treatments of general patterns (switching on-and-off allowed). Requires a large number of treated and control units. Low-rank methods require a large number of untreated observations for each treated unit.
  4. bpCausal: Bayesian panel causal inference with binary treatments following staggered adoption. Requires a large number of pretreatment observations for each treated unit. Suitable when the number of treated units is small.
  5. tjbal: panel causal inference with binary treatments following staggered adoption. Requires a large number of pretreatment periods for each treated unit and a sizable never-treated group.
  6. fdid: implements the factorial difference-in-differences design.

Note that gsynth, fect, and bpCausal all rely on the strict exogeneity assumption (of some form), which corresponds to baseline randomization, while tjbal relies on sequential ignorability, which corresponds to sequential randomization. The table below summarizes their differences.

gsynth fect bpCausal tjbal
Staggered adoption of treatment ✓ ✓ ✓ ✓
General treatment pattern (e.g., switching on and off) ✓
Allow additive fixed effects ✓ ✓ ✓ ✓
Allow feedback from past outcomes to treatment ✓
Allow short pretreatment period (✓)
Accommodate a small number of treated units ✓ ✓
Bayesian uncertainty estimates ✓
Placebo tests for pretrend ✓ ✓ ✓ ✓
Accommodate low-rank structure ✓ ✓ ✓ ✓

Other methods

sconjoint
sconjoint: Structural Conjoint

sconjoint implements structural conjoint, the structural deep learning estimator for forced-choice conjoint experiments. The estimator embeds a deep neural network inside a random-utility logit so that each respondent’s preference vector varies smoothly and flexibly with her observed covariates.

R / Paper
ivDiag
ivDiag: Estimation and Diagnostics for IV Designs

ivDiag provides estimation and diagnostic tools for instrumental variables designs, including bootstrapped confidence intervals, effective F-statistics, Anderson-Rubin test, F-dependent valid t-ratio test, and local-to-zero tests.

R / Stata / Stata code / Paper
hbal
hbal: Hierarchically Regularized Entropy Balancing

hbal implements hierarchically regularized entropy balancing, which hierarchically regularizes higher-order moment constraints of observed covariates. It improves both the feasibility and efficiency of entropy balancing and requires much less computational resources than kernel balancing.

R / Paper
interflex
interflex: Flexibly Estimating Conditional Marginal Effects

interflex estimates and visualizes conditional marginal effects and performs diagnostics. It is the winner of the Best Statistical Software Award from the Society for Political Methodology for 2023.

R / Stata / Paper

Questions and bug reports

Questions about usage and bug reports are welcome.

  • Please post them as an issue on the package’s GitHub repository rather than by email, so others who run into the same problem can find the answer.
  • If a method gives an error on your data, first install the development version from the package’s dev branch, for example:

    devtools::install_github("xuyiqing/fect@dev")
    

    The problem may already be fixed.

  • For the panel-data packages (fect, gsynth, fdid, tjbal, bpCausal), please include a treatment status plot generated by panelView with your issue. It helps us diagnose the problem more quickly.