# NOT RUN {
# This example replicates a result from the Supplementary Appendix
# by Ramey and Zubairy (2018) (RZ-18).
# Load data
ag_data <- ag_data
sample_start <- 7
sample_end <- dim(ag_data)[1]
# Endogenous data
endog_data <- ag_data[sample_start:sample_end,3:5]
# Shock ('Instrument')
shock <- ag_data[sample_start:sample_end, 3]
# Estimate linear model
results_lin_iv <- lp_lin_iv(endog_data,
lags_endog_lin = 4,
instr = shock,
exog_data = NULL,
lags_exog = NULL,
contemp_data = NULL,
lags_criterion = NaN,
max_lags = NaN,
trend = 0,
confint = 1.96,
hor = 20,
num_cores = NULL)
# Make and save plots
iv_lin_plots <- plot_lin(results_lin_iv)
# * The first element of 'iv_lin_plots' shows the response of the first
# variable (Gov) to the chosen (instrument-)shock (here Gov).
# * The second element of 'iv_lin_plots' shows the response of the second
# variable (Tax) to the chosen (instrument-)shock (Gov).
# * ...
# This plot replicates the left plot in the mid-panel of Figure 12 in the
# Supplementary Appendix by RZ-18.
iv_lin_plots[[1]]
# Show all impulse responses by using 'ggpubr' and 'gridExtra'
# The package does not depend on those packages so they have to be installed
library(ggpubr)
library(gridExtra)
lin_plots_all <- sapply(iv_lin_plots, ggplotGrob)
marrangeGrob(lin_plots_all, nrow = ncol(endog_data), ncol = 1, top = NULL)
# }
Run the code above in your browser using DataLab