Learn R Programming

twfeivdecomp (version 0.1.0)

twfeiv_decomp: DID-IV decomposition

Description

twfeiv_decomp() is a function that decomposes the TWFEIV estimator into all possible Wald-DID estimators.

Usage

twfeiv_decomp(formula, data, id_var, time_var, summary_output = FALSE)

Value

If no control variables are included in the formula, the function returns a data frame named exposed_unexposed_combinations which contains the Wald-DID estimates and corresponding weights for each exposed/unexposed cohort pair.

If control variables are included, the function returns a list named decomposition_list containing:

within_IV_coefficient

Numeric. The coefficient from the within-IV regression.

between_IV_coefficient

Numeric. The coefficient from the between-IV regression.

Omega

Numeric. The weight on the within-IV coefficient in the TWFEIV estimator, such that \(TWFEIV = \Omega \times \text{within} + (1 - \Omega) \times \text{between}\).

exposed_unexposed_combinations

A data.frame with the between-IV coefficients and corresponding weights for each exposed/unexposed cohort pair.

Arguments

formula

A formula object of the form Y ~ D + controls | controls + Z, where:

  • Y is the outcome variable,

  • D is the treatment variable,

  • Z is a binary instrumental variable, and

  • controls are optional control variables. Do not include fixed effects (e.g., individual or time dummies) in the control variables.

data

A data frame containing all variables used in the formula, as well as the variables specified by id_var and time_var.

id_var

The name of id variable.

time_var

The name of time variable.

summary_output

Logical. If TRUE, prints a summary table showing, for each design type, the total weight and the weighted average of the Wald-DID estimates. If FALSE (the default), no summary is printed.

Examples

Run this code
# Load example dataset
data(simulation_data)
head(simulation_data)

# Example without controls
decomposition_result_without_controls <- twfeiv_decomp(outcome ~ treatment | instrument,
                                      data = simulation_data,
                                      id_var = "id",
                                      time_var = "time")

# Example with controls
decomposition_result_with_controls <- twfeiv_decomp(
  outcome ~ treatment + control1 + control2 |control1 + control2 + instrument,
  data = simulation_data,
  id_var = "id",
  time_var = "time"
)

Run the code above in your browser using DataLab