Skip to contents

Tests the parallel trends assumption by performing a joint F-test of pre-treatment coefficients and optionally running sensitivity analysis via HonestDiD. Accepts either a fixest model object or manually supplied coefficient estimates and variance-covariance matrix.

Usage

test_pretrends(
  model = NULL,
  betahat = NULL,
  sigma = NULL,
  pre_periods = NULL,
  conf_level = 0.95,
  honest_did = FALSE
)

Arguments

model

A fixest model object from feols. If NULL, betahat and sigma must be provided.

betahat

Numeric vector of pre-treatment coefficient estimates. Used only when model is NULL.

sigma

Variance-covariance matrix for betahat. Used only when model is NULL.

pre_periods

Integer vector indicating which coefficients are pre-treatment. If NULL (default), auto-detected from negative period names in the fixest model (e.g., coefficients containing "-1", "-2", etc.).

conf_level

Numeric. Confidence level for individual tests. Default is 0.95.

honest_did

Logical. If TRUE and the HonestDiD package is installed, run sensitivity analysis using HonestDiD::createSensitivityResults. Default is FALSE.

Value

A list with components:

joint_test

A list with f_stat, df1, df2, and p_value from the joint F-test of pre-treatment coefficients equal to zero.

individual_tests

A data frame with columns term, estimate, std_error, t_stat, p_value, ci_lower, ci_upper for each pre-treatment coefficient.

plot

A ggplot2 object showing pre-treatment coefficients with confidence intervals and a reference line at zero.

honest_did

If requested and available, results from HonestDiD sensitivity analysis. Otherwise NULL.

Examples

if (FALSE) { # \dontrun{
data(base_stagg, package = "fixest")
mod <- feols(y ~ i(time_to_treatment, ref = -1) | id + year,
             data = base_stagg)
result <- test_pretrends(mod)
result$joint_test
result$plot

# Manual input
result2 <- test_pretrends(
  betahat = c(-0.02, 0.01, -0.03),
  sigma = diag(c(0.01, 0.01, 0.01)),
  pre_periods = 1:3
)
} # }