Fused Extended Two-Way Fixed Effects

The {fetwfe} package implements fused extended two-way fixed effects (FETWFE), a methodology for estimating treatment effects in difference-in-differences with staggered adoptions.

fetwfePackage

To install the {fetwfe} package, simply use

# install.packages("remotes")  # if needed
remotes::install_github("gregfaletto/fetwfePackage")
library(fetwfe)

The {fetwfe} package contains one function, fetwfe(), which implements fused extended two-way fixed effects. Here’s some example code that implements the data application from the paper:

library(fetwfe)
library(bacondecomp)

set.seed(23451)

data(divorce)

res <- fetwfe(
    pdata=divorce[divorce$sex == 2, ],
    time_var="year",
    unit_var="st",
    treatment="changed",
    covs=c("murderrate", "lnpersinc", "afdcrolls"),
    response="suiciderate_elast_jag",
    q=0.5,
    verbose=TRUE)

# Average treatment effect on the treated units (in percentage point
# units)
100 * res$att_hat

# Conservative 95% confidence interval for ATT (in percentage point units)

low_att <- 100 * (res$att_hat - qnorm(1 - 0.05 / 2) * res$att_se)
high_att <- 100 * (res$att_hat + qnorm(1 - 0.05 / 2) * res$att_se)

c(low_att, high_att)

# Cohort average treatment effects and confidence intervals (in percentage
# point units)

catt_df_pct <- res$catt_df
catt_df_pct[["Estimated TE"]] <- 100 * catt_df_pct[["Estimated TE"]]
catt_df_pct[["SE"]] <- 100 * catt_df_pct[["SE"]]
catt_df_pct[["ConfIntLow"]] <- 100 * catt_df_pct[["ConfIntLow"]]
catt_df_pct[["ConfIntHigh"]] <- 100 * catt_df_pct[["ConfIntHigh"]]

catt_df_pct

Documentation

Some documentation for the fetwfe() function follows.

Description

This function implements fused extended two-way fixed effects without sample splitting. It estimates the overall average treatment effect on the treated (ATT) as well as the cohort average treatment effects on the treated units (CATT).

Usage

fetwfe(
  pdata,
  time_var,
  unit_var,
  treatment,
  covs,
  response,
  indep_counts = NA,
  sig_eps_sq = NA,
  sig_eps_c_sq = NA,
  lambda.max = NA,
  lambda.min = NA,
  nlambda = 100,
  q = 0.5,
  verbose = FALSE,
  alpha = 0.05
)

Arguments

Value

The function returns a named list with the following components: - att_hat: The estimated overall average treatment effect on the treated. - att_se: The standard error for the overall average treatment effect. If indep_counts is provided, this standard error is asymptotically exact. Otherwise, it is asymptotically conservative. - catt_hats: A named vector containing the estimated average treatment effects for each cohort. - catt_ses: A named vector of standard errors for the cohort average treatment effects, if q is less than 1. - cohort_probs: A vector of the estimated probabilities of being in each cohort, conditional on treatment. These probabilities are calculated from the counts of units in each cohort. - catt_df: A data frame displaying cohort names, cohort average treatment effects, standard errors, and confidence intervals. - beta_hat: The estimated vector of coefficients. - treat_inds: The indices of the coefficients in beta_hat corresponding to the treatment effects for each cohort at each time. - treat_int_inds: The indices of the coefficients in beta_hat corresponding to the interactions between the treatment effects and covariates. - sig_eps_sq: The provided or estimated variance of row-level IID noise. - sig_eps_c_sq: The provided or estimated variance of unit-level IID noise. - lambda.max, lambda.min: The selected or provided values for the penalty parameter lambda. - lambda.max_model_size, lambda.min_model_size, lambda_star_model_size: The sizes of the models corresponding to these penalty parameters. - lambda_star: The penalty parameter lambda selected by BIC. - X_ints: The design matrix containing all interactions, time and cohort dummies, and other variables. - y: The vector of response variables. - X_final, y_final: The transformed design matrix and response vector after applying adjustments. - N, T, R, d, p: The number of units, time periods, treated cohorts, covariates, and features in the final dataset.

References