Learn R Programming

lpirfs (version 0.1.3)

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 as applied in Auerbach and Gorodnichenko (2012).

Usage

lp_nl(endog_data, lags_endog_lin = NULL, lags_endog_nl = NULL,
  lags_criterion = NULL, max_lags = NULL, trend = NULL,
  shock_type = NULL, confint = NULL, hor = NULL, switching = NULL,
  use_hp = NULL, lambda = NULL, gamma = NULL, exog_data = NULL,
  lags_exog = NULL, contemp_data = NULL, num_cores = NULL)

Arguments

endog_data

A data.frame, containing all endogenous variables for the VAR. The Cholesky decomposition is based on the column order.

lags_endog_lin

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

lags_endog_nl

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

lags_criterion

NaN or character. NaN means that the number of lags will be given at lags_endog_nl and lags_endog_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 endog_data. 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 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).

use_hp

Boolean. Use HP-filter? TRUE or FALSE.

lambda

Double. Value of \(\lambda\) for the Hodrick-Prescott filter (if use_hp = TRUE).

gamma

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

exog_data

A data.frame, containing exogenous variables for the VAR. 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

Integer. Number of lags for the exogenous variables.

contemp_data

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

num_cores

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_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 endog_data. 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 endog_data.

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 endog_data. 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 endog_data.

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 endog_data for the plot function. It also contains lagged data (y_nl and x_nl) used for the irf estimations.

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. (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.

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.

Ravn, M.O., Uhlig, H. (2002). "On Adjusting the Hodrick-Prescott Filter for the Frequency of Observations." Review of Economics and Statistics, 84(2), 371-376.

See Also

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

Examples

Run this code
# NOT RUN {
                  ## Example without exogenous variables ##

# Load package
  library(lpirfs)

# Load (endogenous) data
  endog_data <- interest_rules_var_data

# Choose data for switching variable (here Federal Funds Rate)
# Important: The switching variable does not have to be used within the VAR!
 switching_data <-  endog_data$Infl

# Estimate model and save results
  results_nl    <- lp_nl(endog_data,
                                lags_endog_lin  = 4,
                                lags_endog_nl   = 3,
                                lags_criterion  = NaN,
                                max_lags        = NaN,
                                trend           = 0,
                                shock_type      = 1,
                                confint         = 1.96,
                                hor             = 24,
                                switching       = switching_data,
                                use_hp          = TRUE,
                                lambda          = 1600,
                                gamma           = 3,
                                exog_data       = NULL,
                                lags_exog       = NULL,
                                contemp_data    = NULL,
                                num_cores       = NULL)

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

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

# 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(endog_data), ncol = ncol(endog_data), top = NULL)
  marrangeGrob(s2_plots, nrow = ncol(endog_data), ncol = ncol(endog_data), top = NULL)


                     ## Example with exogenous variables ##

# Load (endogenous) data
  endog_data <- interest_rules_var_data

# Choose data for switching variable (here Federal Funds Rate)
# Important: The switching variable does not have to be used within the VAR!
 switching_data <-  endog_data$FF

# Create exogenous data and data with contemporaneous impact (for illustration purposes only)
 exog_data    <- endog_data$GDP_gap*endog_data$Infl*endog_data$FF + rnorm(dim(endog_data)[1])
 contemp_data <- endog_data$GDP_gap*endog_data$Infl*endog_data$FF + rnorm(dim(endog_data)[1])

# Exogenous data has to be a data.frame
 exog_data    <- data.frame(xx  = exog_data)
 contemp_data <- data.frame(cc  = contemp_data)

# Estimate model and save results
 results_nl <- lp_nl(endog_data,
                          lags_endog_lin  = 4,
                          lags_endog_nl   = 3,
                          lags_criterion  = NaN,
                          max_lags        = NaN,
                          trend           = 0,
                          shock_type      = 1,
                          confint         = 1.96,
                          hor             = 24,
                          switching       = switching_data,
                          use_hp          = TRUE,
                          lambda          = 1600, # Ravn and Uhlig (2002):
                                                  # Anuual data    = 6.25
                                                  # Quarterly data = 1600
                                                  # Monthly data   = 129 600
                          gamma           = 3,
                          exog_data       = exog_data,
                          lags_exog       = 3,
                          contemp_data    = NULL,
                          num_cores       = NULL)

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

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

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



# }

Run the code above in your browser using DataLab