Getting Started with fdid

fdid implements the Factorial Difference-in-Differences (FDID) framework from Xu, Zhao, and Ding (2026). For a full tutorial covering all estimators, plotting options, and sensitivity analysis, see the online Quarto book.

Quick example

library(fdid)
data(fdid)   # loads `mortality`

# Unique unit ID and binary treatment factor
mortality$uniqueid <- paste(mortality$provid, mortality$countyid, sep = "-")
mortality$G <- as.integer(mortality$pczupu >= median(mortality$pczupu, na.rm = TRUE))

# Prepare wide-format data
s <- fdid_prepare(
  data       = mortality,
  Y_label    = "mortality",
  X_labels   = c("avggrain", "nograin", "urban", "dis_bj",
                 "dis_pc", "rice", "minority", "edu", "lnpop"),
  G_label    = "G",
  unit_label = "uniqueid",
  time_label = "year"
)

# Estimate
result <- fdid(s, tr_period = 1958:1961, ref_period = 1957)
summary(result)
#> 
#>   Factorial Difference-in-Differences (FDID) Summary
#>   ════════════════════════════════════════════════════════════════════════ 
#>   Method:             ols1 
#>   Variance Type:      robust 
#>   Reference Period:   1957 
#>   Pre-Event Period:   1954, 1955, 1956, 1957 
#>   Event Period:       1958, 1959, 1960, 1961 
#>   Post-Event Period:  1962, 1963, 1964, 1965, 1966 
#>   ════════════════════════════════════════════════════════════════════════ 
#> 
#>   Aggregate Estimates
#>   ──────────────────────────────────────────────────────────────────────── 
#>                       Estimate    Std.Error     95% CI 
#>   ──────────────────────────────────────────────────────────────────────── 
#>   Pre-Event             0.3334       0.2103  [-0.0793, 0.7462] 
#>   Event                -2.8024       0.7511  [-4.2766, -1.3283] 
#>   Post-Event           -0.4893       0.2025  [-0.8866, -0.0920] 
#>   ──────────────────────────────────────────────────────────────────────── 
#> 
#>   Dynamic Estimates
#>   ──────────────────────────────────────────────────────────────────────── 
#>                       Estimate    Std.Error     95% CI 
#>   ──────────────────────────────────────────────────────────────────────── 
#>   1954                  0.9565       0.2716  [0.4235, 1.4896] 
#>   1955                  0.2512       0.2663  [-0.2715, 0.7740] 
#>   1956                 -0.2074       0.2697  [-0.7367, 0.3218] 
#>   1957                  0.0000       0.0000  [0.0000, 0.0000] 
#>    ···································································· 
#>   1958                 -0.8928       0.3800  [-1.6386, -0.1470] 
#>   1959                 -3.5169       1.1051  [-5.6857, -1.3481] 
#>   1960                 -5.6338       1.6781  [-8.9271, -2.3404] 
#>   1961                 -1.1662       0.7263  [-2.5915, 0.2592] 
#>    ···································································· 
#>   1962                 -0.1948       0.3285  [-0.8395, 0.4499] 
#>   1963                 -0.5807       0.2601  [-1.0911, -0.0703] 
#>   1964                 -0.7401       0.2537  [-1.2380, -0.2421] 
#>   1965                 -0.4843       0.2185  [-0.9131, -0.0555] 
#>   1966                 -0.4466       0.2183  [-0.8751, -0.0180] 
#>   ────────────────────────────────────────────────────────────────────────
plot(result, type = "raw")
plot(result, type = "dynamic")

References

Xu, Y., Zhao, S., and Ding, P. (2026). “Factorial Difference-in-Differences.” Journal of the American Statistical Association. https://doi.org/10.1080/01621459.2026.2628343