Learn R Programming

fect (version 2.0.5)

effect: Calculate Cumulative or Sub-group Treatment Effects

Description

Calculates cumulative or average treatment effects for specified units and time periods based on a fitted fect object. The function supports both cumulative effects over time and period-specific average treatment effects, with bootstrap-based uncertainty estimates.

Usage

effect(
  x,
  cumu = TRUE,
  id = NULL,
  period = NULL,
  plot = FALSE,
  count = TRUE,
  xlab = NULL,
  ylab = NULL,
  main = NULL
)

Value

Returns a list containing:

eff

Vector of point estimates for cumulative or average treatment effects.

est.eff

Matrix containing the following columns:

  • ATT: Point estimates

  • S.E.: Standard errors

  • CI.lower: Lower bound of confidence interval

  • CI.upper: Upper bound of confidence interval

  • p.value: Two-sided p-values

Arguments

x

A fect object containing treatment effect estimates and bootstrap results.

cumu

Logical. If TRUE (default), calculates cumulative treatment effects. If FALSE, calculates period-specific average treatment effects.

id

Character vector or NULL. Unit identifiers to include in the analysis. If NULL (default), all treated units are included.

period

Numeric vector of length 2 specifying the time window c(start, end) for effect calculation. If NULL, uses the maximum possible window based on the data.

plot

Logical. If TRUE, creates a visualization of the cumulative treatment effects with confidence intervals and a bar chart showing the number of treated units at each time point. Default is FALSE.

count

Logical. If TRUE, shows the count bars in the plot.

xlab

Character. X-axis label for the plot.

ylab

Character. Y-axis label for the plot.

main

Character. Main title for the plot.

Warning

The function will stop with an error if:

  • No bootstrap results are available in the input object

  • The panel contains treatment reversals

  • The specified ending period exceeds the maximum available period

Author

Shiyun Hu, Licheng Liu, Ye Wang, and Yiqing Xu

Details

The function processes treatment effects in several steps:

1. Selects units based on the id parameter or includes all treated units if id = NULL.

2. Calculates relative time to treatment for each unit.

3. If cumu = TRUE, computes cumulative effects by summing average effects up to each period.

4. Performs bootstrap analysis to estimate uncertainty (standard errors, confidence intervals, and p-values).

The function supports different inference methods (bootstrap, jackknife, parametric) and adjusts calculations accordingly.

Note: The function requires bootstrap results in the input fect object (keep.sims = TRUE must be set when fitting the model).

References

Liu, L., Wang, Y., & Xu, Y. (2022). A Practical Guide to Counterfactual Estimators for Causal Inference with Time-Series Cross-Sectional Data. American Journal of Political Science, 68(1), 160-176.

See Also

fect, plot.fect

Examples

Run this code
if (FALSE) {
# Fit fect model with bootstrap
fit <- fect(Y ~ D + X, data = panel_data, keep.sims = TRUE)

# Calculate cumulative effects for all treated units
results <- effect(fit)

# Calculate period-specific effects for specific units
results_specific <- effect(fit,
                          cumu = FALSE,
                          id = c("unit1", "unit2"),
                          period = c(1, 4))

# View results
print(results$est.catt)
}

Run the code above in your browser using DataLab