Linear panel models, and the event-study plots that often accompanythem, are popular tools for learning about policy effects.
eventstudyr facilitates estimating linear panelevent-study models and constructing event-study plots following thesuggestions inFreyaldenhovenet al. (2021). In particular, it provides functionalityfor:
We will use theexample_data dataset to demonstrate thebasic functionality ofeventstudyr. These sample data arefrom thereplicationarchive for Freyaldenhoven et al. (2021). The documentation can beaccessed using?example_data.
head(example_data)#> # A tibble: 6 × 12#> id eventtime t z y_base eta_m y_jump_m y_smooth_m x_jump_m eta_r#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>#> 1 1 32 1 0 -0.609 0.180 41.6 41.6 0.684 1#> 2 1 32 2 0 -0.870 0.180 41.3 41.3 0.0167 1#> 3 1 32 3 0 -0.906 0.180 41.3 41.3 0.153 1#> 4 1 32 4 0 0.148 0.180 42.3 42.3 -0.930 1#> 5 1 32 5 0 0.579 0.180 42.8 42.8 -0.316 1#> 6 1 32 6 0 -0.340 0.180 41.8 41.8 1.69 1#> # ℹ 2 more variables: y_r <dbl>, x_r <dbl>EventStudy() estimates the regression model fromEquation (2) in Freyaldenhoven et al. (2021) and returns a list objectthat stores the estimation results (as an lm() object) as well as thearguments given in the function call. It accepts variables specifyingthe outcome, policy, ID and time variables. One must also specify thenumber of periods in the past before which the past values of the policyare not supposed to affect the value of the outcome and the number ofperiods in the future after which the future values of the policy arenot supposed to affect the value of the outcome today. The functionoptionally accepts variables specifying the controls, the time window,whether fixed effects should be included, and the period to be used fornormalization.
Here is an example using the sample data:
results<-EventStudy(estimator ="OLS",data = example_data,outcomevar ="y_jump_m",policyvar ="z",idvar ="id",timevar ="t",post =3,pre =0)summary(results$output)#>#> Call:#> estimatr::lm_robust(formula = prepared_model_formula, data = prepared_data,#> clusters = get(idvar), fixed_effects = ~get(idvar) + get(timevar),#> se_type = "stata")#>#> Standard error type: stata#>#> Coefficients:#> Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF#> z_lead3 0.2390 0.1433 1.6683 1.016e-01 -0.04891 0.5270 49#> z_fd_lead3 0.1752 0.1618 1.0829 2.842e-01 -0.14997 0.5004 49#> z_fd_lead2 0.1238 0.1748 0.7085 4.820e-01 -0.22744 0.4751 49#> z_fd 0.8309 0.1332 6.2355 1.014e-07 0.56309 1.0986 49#> z_fd_lag1 0.8552 0.1766 4.8419 1.328e-05 0.50024 1.2101 49#> z_fd_lag2 0.6326 0.1538 4.1123 1.491e-04 0.32347 0.9417 49#> z_fd_lag3 0.2464 0.1830 1.3465 1.843e-01 -0.12132 0.6140 49#> z_lag4 0.1428 0.1270 1.1241 2.664e-01 -0.11244 0.3979 49#>#> Multiple R-squared: 0.9997 , Adjusted R-squared: 0.9997#> Multiple R-squared (proj. model): 0.05327 , Adjusted R-squared (proj. model): -0.001353#> F-statistic (proj. model): 10.44 on 8 and 49 DF, p-value: 2.142e-08results$arguments## Data results$arguments$data[1:5,]#> id eventtime t z y_base eta_m y_jump_m y_smooth_m x_jump_m eta_r#> 1 1 32 1 0 -0.6087238 0.18 41.57128 41.57128 0.68367314 1#> 2 1 32 2 0 -0.8699341 0.18 41.31007 41.31007 0.01667022 1#> 3 1 32 3 0 -0.9059790 0.18 41.27402 41.27402 0.15259252 1#> 4 1 32 4 0 0.1482184 0.18 42.32822 42.32822 -0.93015540 1#> 5 1 32 5 0 0.5785761 0.18 42.75858 42.75858 -0.31635490 1#> y_r x_r z_fd z_fd_lag1 z_fd_lag2 z_fd_lag3 z_fd_lead3 z_fd_lead2#> 1 1.891276 0.5520976 NA NA NA NA 0 0#> 2 1.630066 2.3021448 0 NA NA NA 0 0#> 3 1.594021 1.0289093 0 0 NA NA 0 0#> 4 2.648218 0.2615794 0 0 0 NA 0 0#> 5 3.078576 1.2146608 0 0 0 0 0 0#> z_fd_lead1 z_lag4 z_lead3#> 1 0 NA 1#> 2 0 NA 1#> 3 0 NA 1#> 4 0 NA 1#> 5 0 0 1EventStudyPlot() prepares an event-study plot based onthe suggestions in Freyaldenhoven et al. (2021).
This function is designed to use the output of theEventStudy() and returns a ggplot object. Here is anexample of using the function with some default settings:
eventstudy_estimates_ols<-EventStudy(estimator ="OLS",data = example_data,outcomevar ="y_jump_m",policyvar ="z",idvar ="id",timevar ="t",post =3,pre =0)EventStudyPlot(estimates = eventstudy_estimates_ols,xtitle ="Event time",ytitle ="Coefficient")Freyaldenhoven, S., Hansen, C., Pérez, J.P. and Shapiro, J.M., 2021.Visualization, identification, and estimation in the linear panelevent-study design (No. w29170). National Bureau of EconomicResearch.