Learn R Programming

lpirfs (version 0.1.0)

lp_nl: Compute nonlinear impulse responses

Description

Compute nonlinear impulse responses with local projections by Jord<U+00E0> (2005). The data are separated into two states via a smooth transition function, applied in Auerbach and Gorodnichenko (2012).

Usage

lp_nl(data_set_df, lags_lin = NULL, lags_nl = NULL, lags_criterion = NULL,
  max_lags = NULL, trend = NULL, shock_type = NULL, confint = NULL,
  hor = NULL, switching = NULL, hp_filter = NULL, lambda = NULL,
  gamma = NULL)

Arguments

data_set_df

A data.frame() containing all endogenous variables for the VAR. The column order is used for the Cholesky decomposition.

lags_lin

NaN or integer. NaN if lag length criterion is used. Integer for number of lags for linear VAR to identify shock.

lags_nl

NaN or integer. Number of lags for nonlinear VAR (if lags_criterion = NaN). NaN if lag length criterion is given.

lags_criterion

NaN or character. NaN means that the number of lags will be given at lags_nl and lags_lin. The lag length criteria are 'AICc', 'AIC' and 'BIC'.

max_lags

NaN or integer. Maximum number of lags (if lags_criterion = 'AICc', 'AIC', 'BIC'). NaN otherwise.

trend

Integer. Include no trend = 0 , include trend = 1, include trend and quadratic trend = 2.

shock_type

Integer. Standard deviation shock = 0, unit shock = 1.

confint

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

hor

Integer. Number of horizons for impulse responses.

switching

Numeric vector. A column vector with the same length as data_set_df. This series can either be decomposed via the Hodrick-Prescott filter (see Auerbach and Gorodnichenko, 2013) or directly plugged into the following smooth transition function: $$ F_{z_t} = \frac{exp(-\gamma z_t)}{1 + exp(-\gamma z_t)} $$ Warning: \(F_{z_t}\) will be lagged in create_nl_data by one and then multiplied with the data. If the variable shall not be lagged, the vector has to be given with a lead of one. The data for the two regimes are: Regime 1 = (1-\(F(z_{t-1})\))*y_t-p, Regime 2 = \(F(z_{t-1})\)*y_t-p.

hp_filter

Integer. No HP-filter = 0. Use HP-filter = 1.

lambda

Double. Value of \(\lambda\) for the Hodrick-Prescott filter if HP-filter is applied.

gamma

Double. Positive number which is used in the transition function.

Value

A list with impulse responses and their robust confidence bands. It also contains a list named specs with properties of data_set_df for the plot function.

irf_s1_mean

A three 3D array() containing all impulse responses for all endogenous variables of the first state. The last dimension denotes the shock variable. The row in each matrix denotes the responses of the ith variable, ordered as in data_set_df. The columns are the horizons. For example, if the results are saved in results_nl, results_nl$irf_s1_mean[, , 1] returns a KXH matrix, where K is the number of variables and H the number of horizons. '1' is the shock variable, corresponding to the variable in the first column of data_set_df.

irf_s1_low

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

irf_s1_up

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

irf_s2_mean

A three 3D array() containing all impulse responses for all endogenous variables of the second state. The last dimension denotes the shock variable. The row in each matrix denotes the responses of the ith variable, ordered as in data_set_df. The columns denote the horizon. For example, if the results are saved in results_nl, results_nl$irf_s2_mean[, , 1] returns a KXH matrix, where K is the number of variables and H the number of horizons. '1' is the first shock variable corresponding to the variable in the first column of data_set_df.

irf_s2_low

A three 3D array() containing all lower confidence bands of the responses, based on robust standard errors by Newey and West (1987). Properties are equal to irf_s2_mean.

irf_s2_up

A three 3D array(), containing all upper confidence bands of the responses, based on robust standard errors by Newey and West (1987). Properties are equal to irf_s2_mean.

specs

A list with properties of data_set_df for the plot function.

fz

A vector containing the values of the transition function F(z_t-1).

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.

Auerbach, A. J., and Gorodnichenko Y. (2013). "Fiscal Multipliers in Recession and Expansion." NBER Working Paper Series. Nr 17447.

Hurvich, C. M., and Tsai, C.-L. (1993) <U+201C>A Corrected Akaike Information Criterion for Vector Autoregressive Model Selection.<U+201D> Journal of Time Series Analysis, 1993, 14(3): 271<U+2013>79.

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

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.

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

Examples

Run this code
# NOT RUN {
# Load package
  library(lpirfs)

# Load data
  data_set_df <- monetary_var_data

# Estimate model and save results
  results_nl <- lp_nl(data_set_df, lags_lin       = 4L,
                                   lags_nl        = 3L,
                                   lags_criterion = NaN,
                                   max_lags       = NaN,
                                   trend          = 0L,
                                   shock_type     = 1L,
                                   confint        = 1.96,
                                   hor            = 24L,
                                   switching      = data_set_df$FF,
                                   hp_filter      = 1L,
                                   lambda         = 1600,
                                   gamma          = 3)

# Make and save all plots
  nl_plots <- plot_nl_irfs(results_nl)

# Show all plots
  library(ggpubr)
  library(gridExtra)

# Save plots based on states
  s1_plots <- sapply(nl_plots$gg_s1, ggplotGrob)
  s2_plots <- sapply(nl_plots$gg_s2, ggplotGrob)

# Show first irf of each state
  plot(s1_plots[[1]])
  plot(s2_plots[[1]])

# Show all plots
  marrangeGrob(s1_plots, nrow = ncol(data_set_df), ncol = ncol(data_set_df), top = NULL)
  marrangeGrob(s2_plots, nrow = ncol(data_set_df), ncol = ncol(data_set_df), top = NULL)

# }

Run the code above in your browser using DataLab