Learn R Programming

lpirfs (version 0.1.3)

lp_lin_iv: Compute linear impulse responses with identified shock and/or with 2SLS

Description

Compute linear impulse responses with identified shock and/or with 2SLS.

Usage

lp_lin_iv(endog_data, shock = NULL, instr = NULL, twosls = FALSE,
  instrum = NULL, lags_endog_lin = NULL, exog_data = NULL,
  lags_exog = NULL, contemp_data = NULL, lags_criterion = NaN,
  max_lags = NaN, trend = NULL, confint = NULL, hor = NULL,
  num_cores = NULL)

Arguments

endog_data

A data.frame, containing the values of the dependent variable(s).

shock

A one column data.frame, including the variable to shock with. The row length has to be the same as endog_data. When twosls = TRUE, this variable will be approximated/regressed on the instrument variable(s) given in instrum.

instr

Deprecated input name. Use shock instead. See shock for details.

twosls

Use two stage least squares? TRUE or FALSE.

instrum

A data.frame, containing the instrument(s) to use for 2SLS. This instrument will be used for the variable in shock.

lags_endog_lin

NaN or integer. NaN if lags are chosen by a lag length criterion. Integer for number of lags for endog_data.

exog_data

A data.frame, containing exogenous variables. The row length has to be the same as endog_data. Lag lengths for exogenous variables have to be given and will no be determined via a lag length criterion.

lags_exog

NULL or Integer. Integer for the number of lags for the exogenous data.

contemp_data

A data.frame, containing exogenous data with contemporaneous impact. The row length has to be the same as endog_data.

lags_criterion

NaN or character. NaN means that the number of lags will be given at lags_endog_lin. Possible lag length criteria are 'AICc', 'AIC' or 'BIC'. Note that when twosls = TRUE, the lag lengths are chosen based on normal OLS regressions, without using the instruments.

max_lags

NaN or integer. Maximum number of lags if lags_criterion is a character denoting the lag length criterion. NaN otherwise.

trend

Integer. No trend = 0 , include trend = 1, include trend and quadratic trend = 2.

confint

Double. Width of confidence bands. 68% = 1; 90% = 1.65; 95% = 1.96.

hor

Integer. Number of horizons for impulse responses.

num_cores

NULL or Integer. The number of cores to use for the estimation. If NULL, the function will use the maximum number of cores minus one.

Value

A list containing:

irf_lin_mean

A matrix, containing the impulse responses. The row in each matrix denotes the response of the ith variable to the shock. The columns are the horizons.

irf_lin_low

A matrix, containing all lower confidence bands of the impulse responses, based on robust standard errors by Newey and West (1987). Properties are equal to irf_lin_mean.

irf_lin_up

A matrix, containing all upper confidence bands of the impulse responses, based on robust standard errors by Newey and West (1987). Properties are equal to irf_lin_mean.

specs

A list with properties of endog_data for the plot function. It also contains lagged data (y_lin and x_lin) used for the estimations of the impulse responses.

References

Akaike, H. (1974). "A new look at the statistical model identification", IEEE Transactions on Automatic Control, 19 (6): 716<U+2013>723.

Auerbach, A. J., and Gorodnichenko, Y. (2012). "Measuring the Output Responses to Fiscal Policy." American Economic Journal: Economic Policy, 4 (2): 1-27.

Blanchard, O., and Perotti, R. (2002). <U+201C>An Empirical Characterization of the Dynamic Effects of Changes in Government Spending and Taxes on Output.<U+201D> Quarterly Journal of Economics, 117(4): 1329<U+2013>1368.

Hurvich, C. M., and Tsai, C.-L. (1989), "Regression and time series model selection in small samples", Biometrika, 76(2): 297<U+2013>307

Jord<U+00E0>, <U+00D2>. (2005). "Estimation and Inference of Impulse Responses by Local Projections." American Economic Review, 95 (1): 161-182.

Jord<U+00E0>, <U+00D2>, Schularick, M., Taylor, A.M. (2015), "Betting the house", Journal of International Economics, 96, S2-S18.

Newey, W.K., and West, K.D. (1987). <U+201C>A Simple, Positive-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix.<U+201D> Econometrica, 55: 703<U+2013>708.

Ramey, V.A., and Zubairy, S. (2018). "Government Spending Multipliers in Good Times and in Bad: Evidence from US Historical Data." Journal of Political Economy, 126(2): 850 - 901.

Schwarz, Gideon E. (1978). "Estimating the dimension of a model", Annals of Statistics, 6 (2): 461<U+2013>464.

See Also

https://adaemmerp.github.io/lpirfs/README_docs.html

Examples

Run this code
# 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]

# Variable to shock with. Here government spending due to
# Blanchard and Perotti (2002) framework
 shock         <- ag_data[sample_start:sample_end, 3]

# Estimate linear model
 results_lin_iv <- lp_lin_iv(endog_data,
                               lags_endog_lin = 4,
                               shock          = 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  shock (Gov).
# * The second element of 'iv_lin_plots' shows the response of the second
#   variable (Tax) to the 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'
# lpirfs 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)


## Add lags of the identified shock ##

# Endogenous data but now exclude government spending
 endog_data    <- ag_data[sample_start:sample_end, 4:5]

# Variable to shock with (government spending)
 shock         <- ag_data[sample_start:sample_end, 3]

# Add the shock variable to exogenous data
 exog_data     <- shock

# Estimate linear model with lagged shock variable
 results_lin_iv <- lp_lin_iv(endog_data,
                               lags_endog_lin = 4,
                               shock          = shock,
                               exog_data      = exog_data,
                               lags_exog      = 2,
                               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)
 lin_plots_all   <- sapply(iv_lin_plots, ggplotGrob)
 marrangeGrob(lin_plots_all, nrow = ncol(endog_data), ncol = 1, top = NULL)


##############################################################################
#####                         Use 2SLS                               #########
##############################################################################

# Set seed
 set.seed(007)

# 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]

# Variable to shock with (government spending)
 shock         <- ag_data[sample_start:sample_end, 3]

# Generate instrument variable that is correlated with government spending
 instrum       <- as.data.frame(0.9*shock$Gov + rnorm(length(shock$Gov), 0, 0.02) )

# Estimate linear model via SLS
 results_lin_iv <- lp_lin_iv(endog_data,
                            lags_endog_lin = 4,
                            shock          = shock,
                            instrum        = instrum,
                            twosls         = TRUE,
                            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)

# Create all plots
 iv_lin_plots    <- plot_lin(results_lin_iv)


# Show response of GDP
 iv_lin_plots[[3]]
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab