Perform sensitivity analysis with Sun and Abraham (fixest package)
masterTo use HonestDiD with the fixest package's Sun and Abraham method, you must first extract the aggregated event-study coefficients and their variance-covariance matrix using a helper function (e.g., sunab_beta_vcv).
- Run a
fixest::feolsregression using thesunaboption. - Use the extraction function to get
betaandsigma. - Pass these to
HonestDiD::constructOriginalCSandHonestDiD::createSensitivityResults_relativeMagnitudesto perform the sensitivity analysis. - Visualize the results using
HonestDiD::createSensitivityPlot_relativeMagnitudes.
# 1. Run fixest with sunab
df$year_treated <- ifelse(is.na(df$yexp2), Inf, df$yexp2)
formula_sunab <- dins ~ sunab(year_treated, year) | stfips + year
res_sunab <- fixest::feols(formula_sunab, cluster="stfips", data=df)
# 2. Extract the beta and vcv (using the provided sunab_beta_vcv function)
beta_vcv <- sunab_beta_vcv(res_sunab)
# 3. Run sensitivity analysis for relative magnitudes
kwargs <- list(betahat = beta_vcv$beta,
sigma = beta_vcv$sigma,
numPrePeriods = sum(beta_vcv$cohorts < 0),
numPostPeriods = sum(beta_vcv$cohorts > -1))
extra <- list(Mbarvec=seq(from = 0.5, to = 2, by = 0.5), gridPoints=100)
original_results <- do.call(HonestDiD::constructOriginalCS, kwargs)
sensitivity_results <- do.call(HonestDiD::createSensitivityResults_relativeMagnitudes,
c(kwargs, extra))
# 4. Plot
HonestDiD::createSensitivityPlot_relativeMagnitudes(sensitivity_results, original_results)