EventStudy {eventstudyr} | R Documentation |
Estimates Equation (2) in Freyaldenhoven et al. (2021)
Description
EventStudy
uses regression methods to estimate the effect of a policy on a given outcome.
Usage
EventStudy(
estimator,
data,
outcomevar,
policyvar,
idvar,
timevar,
controls = NULL,
proxy = NULL,
proxyIV = NULL,
FE = TRUE,
TFE = TRUE,
post,
overidpost = 1,
pre,
overidpre = post + pre,
normalize = -1 * (pre + 1),
cluster = TRUE,
anticipation_effects_normalization = TRUE
)
Arguments
estimator |
Accepts one of "OLS" or "FHS". If "OLS" is specified, implements Ordinary Least Squares. If "FHS" is specified, implements Instrumental Variables (IV) estimator proposed in Freyaldenhoven Hansen Shapiro (FHS, 2019). |
data |
Data frame containing the variables of interest. |
outcomevar |
Character indicating column of outcome variable y. |
policyvar |
Character indicating column of policy variable z. |
idvar |
Character indicating column of units. |
timevar |
Character indicating column of time periods. |
controls |
Optional character vector indicating a set of control variables q. |
proxy |
Character indicating column of variable that is thought to be affected by the confound but not by the policy. Should be specified if and only if estimator is specified as "FHS". |
proxyIV |
Character of column to be used as an instrument. Should be specified if and only if estimator is specified as "FHS". If NULL, defaults to the strongest lead of the policy variable based on the first stage. |
FE |
Logical indicating whether unit fixed-effects should be included. Defaults to TRUE. |
TFE |
Logical indicating whether time fixed-effects should be included. Defaults to TRUE. |
post |
Whole number indicating the number of periods in the past before which the past values of the policy are not supposed to affect the value of the outcome. Corresponds to M in equation (2) of Freyaldenhoven et al. (2021). |
overidpost |
Optional whole number indicating the number of event times after "post" to be included in estimation. Defaults to 1. Corresponds to L_M in equation (2) of Freyaldenhoven et al. (2021). |
pre |
Whole number indicating the number of periods in the future after which the future values of the policy are not supposed to affect the value of the outcome today. Corresponds to G in equation (2) of Freyaldenhoven et al. (2021). |
overidpre |
Optional whole number indicating the number of event times earlier than -"pre" to be included in estimation. Defaults to "post" + "pre". Corresponds to L_G in equation (2) of Freyaldenhoven et al. (2021). |
normalize |
Specifies the event-time coefficient to be normalized. Defaults to - pre - 1. |
cluster |
Logical indicating whether to use clustered errors by units. If FALSE, will use unclustered heteroskedasticity-robust standard errors. Defaults to TRUE. Must be TRUE if FE is TRUE. |
anticipation_effects_normalization |
If set to TRUE, runs the default process and switches coefficient to be normalized to 0 when there are anticipation effects. If set to FALSE, does not make the switch. Defaults to TRUE. |
Value
A list that contains, under "output", the estimation output as an lm_robust object, and under "arguments", the arguments passed to the function.
Examples
# A minimal example
eventstudy_model <-
EventStudy(
estimator = "OLS",
data = example_data,
outcomevar = "y_base",
policyvar = "z",
idvar = "id",
timevar = "t",
pre = 0, post = 3,
normalize = -1
)
### Access estimated model
eventstudy_model$output
summary(eventstudy_model$output)
### data.frame of estimates
estimatr::tidy(eventstudy_model$output)
### Access arguments
eventstudy_model$arguments
# A dynamic OLS model with anticipation effects and controls
eventstudy_model_dyn <-
EventStudy(
estimator = "OLS",
data = example_data,
outcomevar = "y_base",
policyvar = "z",
idvar = "id",
timevar = "t",
controls = "x_r",
FE = TRUE, TFE = TRUE,
post = 3, overidpost = 5,
pre = 2, overidpre = 4,
normalize = - 3,
cluster = TRUE,
anticipation_effects_normalization = TRUE
)
summary(eventstudy_model_dyn$output)
# A static model
eventstudy_model_static <-
EventStudy(
estimator = "OLS",
data = example_data,
outcomevar = "y_jump_m",
policyvar = "z",
idvar = "id",
timevar = "t",
FE = TRUE, TFE = TRUE,
post = 0, overidpost = 0,
pre = 0, overidpre = 0,
cluster = TRUE
)
summary(eventstudy_model_static$output)
# A dynamic model with an unbalanced panel
data_unbal <- example_data[1:(nrow(example_data)-1),] # drop last row to make unbalanced
eventstudy_model_unbal <-
EventStudy(
estimator = "OLS",
data = data_unbal,
outcomevar = "y_base",
policyvar = "z",
idvar = "id",
timevar = "t",
pre = 0, post = 3,
normalize = -1
)
summary(eventstudy_model_unbal$output)
# A dynamic model estimated using IV
eventstudy_model_iv <-
EventStudy(
estimator = "FHS",
data = example_data,
outcomevar = "y_base",
policyvar = "z",
idvar = "id",
timevar = "t",
proxy = "x_r",
FE = TRUE, TFE = TRUE,
post = 2, overidpost = 1,
pre = 0, overidpre = 3,
normalize = -1,
cluster = TRUE
)
summary(eventstudy_model_iv$output)