fdid: Factorial Difference-in-Differences Estimation

View source: R/fdid.R

fdidR Documentation

Factorial Difference-in-Differences Estimation

Description

Performs factorial difference-in-differences (FDID) estimation using various methods and variance estimation techniques.

Usage

fdid(
  s,
  tr_period,
  ref_period,
  entire_period = NULL,
  method = "ols1",
  vartype = "robust",
  missing_data = c("listwise", "available"),
  nsims = 1000,
  parallel = FALSE,
  cores = 2,
  target.pop = c("all", "1", "0")
)

Arguments

s

A data frame prepared using fdid_prepare.

tr_period

A numeric vector specifying the treatment periods.

ref_period

A numeric scalar specifying the reference period.

entire_period

A numeric vector specifying the total range of time periods. If NULL, estimation is performed on all available time periods. Example: c(1958, 1959, 1960, 1961).

method

A string specifying the estimation method. Options: "ols1", "ols2", "did", "ebal", "ipw", "aipw". Default is "ols1".

vartype

A string specifying the variance estimation type. Options: "robust", "bootstrap", "jackknife". Default is "robust".

missing_data

How to handle missing data. Two options:

  • "listwise": Drop any row missing any relevant column (including outcomes in the periods used).

  • "available": Drop rows only if they are missing in group/covariates/cluster columns, but allow partial usage of outcomes.

Default is "listwise".

nsims

Number of simulations for bootstrap variance estimation. Default is 1000.

parallel

Logical; whether to perform parallel computations. Default is FALSE.

cores

Number of cores for parallel computations. Default is 2.

target.pop

Character; the target population for averaging: "all", "1", or "0". "all" corresponds to the full sample. "1" targets the G=1 population. "0" targets the G=0 population. Default is "all".

Value

A list with the following components:

est

A list with three elements: $pre, $event, and $post containing aggregated pre-treatment, overall event, and post-treatment FDID estimates, respectively.

dynamic

Dynamic FDID estimates for each time in entire_period.

raw_means

Raw mean outcomes by group for each time in entire_period.

tr_period

Treatment periods used.

ref_period

Reference period used.

entire_period

All time periods for dynamic estimation.

method

Method used.

vartype

Variance type used.

times

All numeric time columns found.

G

Group indicator (0/1).

ps

Propensity scores (if ipw or aipw method used).

call

The matched call.

target.pop

Character indicating the target population used.

Author(s)

Rivka Lipkovitz, Enhan Liu

Examples


data(fdid)
mortality$uniqueid <- paste(mortality$provid, mortality$countyid, sep = "-")
mortality$G <- ifelse(mortality$pczupu >= median(mortality$pczupu, na.rm = TRUE), 1, 0)
s <- fdid_prepare(
  data = mortality, Y_label = "mortality",
  X_labels = c("avggrain", "lnpop"),
  G_label = "G", unit_label = "uniqueid", time_label = "year"
)
result <- fdid(s, tr_period = 1958:1961, ref_period = 1957)
summary(result)


fdid documentation built on March 23, 2026, 5:07 p.m.