lp_nl_panel: Compute nonlinear impulse responses for panel data

View source: R/lp_nl_panel.R

lp_nl_panelR Documentation

Compute nonlinear impulse responses for panel data

Description

This function estimates nonlinear impulse responses by using local projections for panel data with an identified shock. The data can be separated into two states by a smooth transition function as applied in Auerbach and Gorodnichenko (2012), or by a simple dummy approach.

Usage

lp_nl_panel(
  data_set = NULL,
  data_sample = "Full",
  endog_data = NULL,
  cumul_mult = TRUE,
  shock = NULL,
  diff_shock = TRUE,
  panel_model = "within",
  panel_effect = "individual",
  robust_cov = NULL,
  robust_method = NULL,
  robust_type = NULL,
  robust_cluster = NULL,
  robust_maxlag = NULL,
  use_gmm = FALSE,
  gmm_model = "onestep",
  gmm_effect = "twoways",
  gmm_transformation = "d",
  c_exog_data = NULL,
  l_exog_data = NULL,
  lags_exog_data = NaN,
  c_fd_exog_data = NULL,
  l_fd_exog_data = NULL,
  lags_fd_exog_data = NaN,
  switching = NULL,
  use_logistic = TRUE,
  use_hp = FALSE,
  lag_switching = TRUE,
  lambda = NULL,
  gamma = NULL,
  confint = NULL,
  hor = NULL
)

Arguments

data_set

A data.frame, containing the panel data set. The first column has to be the variable denoting the cross section. The second column has to be the variable denoting the time section.

data_sample

Character or numeric. To use the full sample set value to "Full" (default). To estimate a subset, you have to provide a sequence of dates. This sequence has to be in the same format as the second column (time-section).

endog_data

Character. The column name of the endogenous variable. You can only provide one endogenous variable at a time.

cumul_mult

Boolean. Estimate cumulative multipliers? TRUE (default) or FALSE. If TRUE, cumulative responses are estimated via:

y_{(t+h)} - y_{(t-1)},

where h = 0,..., H-1.

shock

Character. The column name of the variable to shock with.

diff_shock

Boolean. Take first differences of the shock variable? TRUE (default) or FALSE.

panel_model

Character. Type of panel model. The default is "within" (fixed effects). Other options are "random", "ht", "between", "pooling" or "fd". See vignette of the plm package for details.

panel_effect

Character. The effects introduced in the model. Options are "individual" (default), "time", "twoways", or "nested". See the vignette of the plm-package for details.

robust_cov

NULL or Character. The character specifies the method how to estimate robust standard errors: Options are "vcovBK", "vcovDC", "vcovG", "vcovHC", "vcovNW", "vcovSCC". For these options see vignette of plm package. Another option is "Vcxt". For details see Miller (2017) If "use_gmm = TRUE", this option has to be NULL.

robust_method

NULL (default) or Character. The character is an option when robust_cov = "vcovHC". See vignette of the plm package for details.

robust_type

NULL (default) or Character. The character is an option when robust_cov = "vcovBK", "vcovDC", "vcovHC", "vcovNW" or "vcovSCC". See vignette of the plm package for details.

robust_cluster

NULL (default) or Character. The character is an option when robust_cov = "vcovBK", "vcovG" or "vcovHC". See vignette of the plm package for details.

robust_maxlag

NULL (default) or Character. The character is an option when robust_cov = "vcovNW" or "vcovSCC". See vignette of the plm package for details.

use_gmm

Boolean. Use GMM for estimation? TRUE or FALSE (default). See vignette of plm package for details. If TRUE, the option "robust_cov" has to be set to NULL.

gmm_model

Character. Either "onestep" (default) or "twosteps". See vignette of the plm package for details.

gmm_effect

Character. The effects introduced in the model: "twoways" (default) or "individual". See vignette of the plm-package for details.

gmm_transformation

Character. Either "d" (default) for the "difference GMM" model or "ld" for the "system GMM". See vignette of the plm package for details.

c_exog_data

NULL or Character. Name(s) of the exogenous variable(s) with contemporaneous impact.

l_exog_data

NULL or Character. Name(s) of the exogenous variable(s) with lagged impact.

lags_exog_data

Integer. Lag length for the exogenous variable(s) with lagged impact.

c_fd_exog_data

NULL or Character. Name(s) of the exogenous variable(s) with contemporaneous impact of first differences.

l_fd_exog_data

NULL or Character. Name(s) of exogenous variable(s) with lagged impact of first differences.

lags_fd_exog_data

NaN or Integer. Number of lags for variable(s) with impact of first differences.

switching

Character. Column name of the switching variable. If "use_logistic = TRUE", this series can either be decomposed by 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)}.

The data for the two regimes are lagged by default:
Regime 1 = (1-F(z_{t-1}))*y_(t-p),
Regime 2 = F(z_{t-1})*y_(t-p). This option can be suppressed with "lag_switching = FALSE".

use_logistic

Boolean. Use logistic function to separate states? TRUE (default) or FALSE. If FALSE, the values of the switching variable have to be binary (0/1).

use_hp

Boolean. Use HP-filter? TRUE or FALSE (default).

lag_switching

Boolean. Use the first lag of the values of the transition function? TRUE (default) or FALSE.

lambda

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

gamma

Double. Positive value for \gamma, used in the transition function.

confint

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

hor

Integer. Number of horizons for impulse responses.

Value

A list containing:

irf_lin_mean

A matrix, containing the impulse responses. The columns are the horizons.

irf_lin_low

A matrix, containing all lower confidence bands. The columns are the horizons.

irf_lin_up

A matrix, containing all upper confidence bands. The columns are the horizons.

reg_outputs

Full regression output (plm object) for each horizon.

reg_summaries

Summary of regression output for each horizon. In case of robust covariance estimators, this only includes the t-tests.

xy_data_sets

Data sets with endogenous and exogenous variables for each horizon.

specs

A list with data properties for e.g. the plot function.

Author(s)

Philipp Adämmer

References

Croissant, Y., Millo, G. (2008). “Panel Data Econometrics in R: The plm Package.” Journal of Statistical Software, 27(2), 1-43. doi: 10.18637/jss.v027.i02.

Jordà, Ò. (2005). "Estimation and Inference of Impulse Responses by Local Projections." American Economic Review, 95 (1): 161-182.

Jordà, Ò., Schualrick, M., Taylor, A.M. (2018). "Large and State-Dependent Effects of Quasi-Random Monetary Experiments", NBER working paper 23074, FRBSF working paper 2017-02.

Millo, G. (2017). “Robust Standard Error Estimators for Panel Models: A Unifying Approach.” Journal of Statistical Software, 82(3), 1-27. doi: 10.18637/jss.v082.i03.

Examples



#--- Info
# This example is based on a STATA code that has been provided on
# Òscar Jordà's website (https://sites.google.com/site/oscarjorda/home/local-projections)
# It estimates impulse reponses of the ratio of (mortgage lending/GDP) to a
# +1% change in the short term interest rate

#--- Get data
# Go to the website of the 'The MacroFinance and MacroHistory Lab'
# Download the Excel-Sheet of the 'Jordà-Schularick-Taylor Macrohistory Database':
# URL: https://www.macrohistory.net/database/
# Then uncomment and run the code below...


#--- Code

## Load libraries to download and read excel file from the website
#  library(lpirfs)
#  library(readxl)
#  library(dplyr)
#
# Load JST Macrohistory Database
#  jst_data <- read_excel("JSTdatasetR5.xlsx", sheet = "Data")
#
## Choose years <= 2013. Swap the first two columns so that 'country' is the
## first (cross section) and 'year' the second (time section) column
#  jst_data <- jst_data                    %>%
#              dplyr::filter(year <= 2013) %>%
#              dplyr::select(country, year, everything())
#
## Prepare variables. This is based on the 'data.do' file
#   data_set <- jst_data %>%
#                mutate(stir     = stir)                         %>%
#                mutate(mortgdp  = 100*(tmort/gdp))              %>%
#                mutate(hpreal   = hpnom/cpi)                    %>%
#                group_by(country)                               %>%
#                mutate(hpreal   = hpreal/hpreal[year==1990][1]) %>%
#                mutate(lhpreal  = log(hpreal))                  %>%
#
#                mutate(lhpy     = lhpreal - log(rgdppc))        %>%
#                mutate(lhpy     = lhpy - lhpy[year == 1990][1]) %>%
#                mutate(lhpreal  = 100*lhpreal)                  %>%
#                mutate(lhpy     = 100*lhpy)                     %>%
#                ungroup()                                       %>%
#
#                mutate(lrgdp    = 100*log(rgdppc))              %>%
#                mutate(lcpi     = 100*log(cpi)) 		            %>%
#                mutate(lriy     = 100*log(iy*rgdppc))           %>%
#                mutate(cay      = 100*(ca/gdp))                 %>%
#                mutate(tnmort   = tloans - tmort)               %>%
#                mutate(nmortgdp = 100*(tnmort/gdp))             %>%
#                dplyr::select(country, year, mortgdp, stir, ltrate, lhpy,
#                              lrgdp, lcpi, lriy, cay, nmortgdp)
#
#
## Use data_sample from 1870 to 2013 and exclude observations from WWI and WWII
#   data_sample <-   seq(1870, 2016)[!(seq(1870, 2016) %in%
#                                   c(seq(1914, 1918),
#                                   seq(1939, 1947)))]
#
## Estimate panel model
# results_panel <-  lp_nl_panel(data_set           = data_set,
#                                data_sample       = data_sample,
#                                endog_data        = "mortgdp",
#                                cumul_mult        = TRUE,
#
#                                shock             = "stir",
#                                diff_shock        = TRUE,
#                                panel_model       = "within",
#                                panel_effect      = "individual",
#                                robust_cov        = "vcovSCC",
#
#                                switching         = "lrgdp",
#                                lag_switching     = TRUE,
#                                use_hp            = TRUE,
#                                lambda            = 6.25,
#                                gamma             = 10,
#
#                                c_exog_data       = "cay",
#                                c_fd_exog_data    = colnames(data_set)[c(seq(4,9),11)],
#                                l_fd_exog_data    = colnames(data_set)[c(seq(3,9),11)],
#                                lags_fd_exog_data = 2,
#
#                                confint           = 1.67,
#                                hor               = 5)
#
## Plot irfs
#  plot(results_panel)
#
#
## Plot values of the transition function for USA between 1950 and 2016
#  library(ggplot2)
#
#  data_set %>%
#     mutate(fz = results_panel$fz$fz) %>%
#     select(country, year, fz)     %>%
#     filter(country == "USA" & year > 1950  & year <= 2016) %>%
#     ggplot()+
#     geom_line(aes(x = year, y = fz)) +
#     scale_x_continuous(breaks = seq(1950, 2016, 5))
#
#
##############################################################################
###                           Use GMM                                      ###
##############################################################################
#
## Use a much smaller sample to have fewer T than N
#  data_sample <-   seq(2000, 2012)
#
#
## Estimate panel model with gmm
## This example (please uncomment) gives a warning at each iteration.
## The data set is not well suited for
## GMM as GMM is based on N-asymptotics and the data set only contains 27 countries
#
# results_panel <-  lp_nl_panel(data_set           = data_set,
#                               data_sample       = data_sample,
#                               endog_data        = "mortgdp",
#                               cumul_mult        = TRUE,
#
#                               shock             = "stir",
#                               diff_shock        = TRUE,
#
#                               use_gmm            = TRUE,
#                               gmm_model          = "onestep",
#                               gmm_effect         = "twoways",
#                               gmm_transformation = "ld",
#
#                               switching         = "lrgdp",
#                               lag_switching     = TRUE,
#                               use_hp            = TRUE,
#                               lambda            = 6.25,
#                               gamma             = 10,
#
#                               l_exog_data       = "mortgdp",
#                               lags_exog_data    = 1,
#
#                               confint           = 1.67,
#                               hor               = 5)
#
## Create and plot irfs
# plot(results_panel)



lpirfs documentation built on July 9, 2023, 6:35 p.m.