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

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/lp_lin_iv.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
lp_lin_iv(
  endog_data,
  shock = NULL,
  instr = NULL,
  use_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,
  use_nw = TRUE,
  nw_lag = NULL,
  nw_prewhite = FALSE,
  adjust_se = FALSE,
  hor = NULL,
  num_cores = 1
)

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

use_twosls

Boolean. Use two stage least squares? TRUE or FALSE (default).

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

use_nw

Boolean. Use Newey-West (1987) standard errors for impulse responses? TRUE (default) or FALSE.

nw_lag

Integer. Specifies the maximum lag with positive weight for the Newey-West estimator. If set to NULL (default), the lag increases with with the number of horizon.

nw_prewhite

Boolean. Should the estimators be pre-whitened? TRUE of FALSE (default).

adjust_se

Boolen. Should a finite sample adjsutment be made to the covariance matrix estimators? TRUE or FALSE (default).

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, and the selected lag lengths when an information criterion has been used.

Author(s)

Philipp Adämmer

References

Akaike, H. (1974). "A new look at the statistical model identification", IEEE Transactions on Automatic Control, 19 (6): 716–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). “An Empirical Characterization of the Dynamic Effects of Changes in Government Spending and Taxes on Output.” Quarterly Journal of Economics, 117(4): 1329–1368.

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

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

Jordà, Ò, Schularick, M., Taylor, A.M. (2015), "Betting the house", Journal of International Economics, 96, S2-S18.

Newey, W.K., and West, K.D. (1987). “A Simple, Positive-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix.” Econometrica, 55: 703–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–464.

See Also

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

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
# 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,
                               trend          = 0,
                               confint        = 1.96,
                               hor            = 20)

# Show all impulse responses
 plot(results_lin_iv)

# 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 diagnostics. The first element shows the reaction of the first given endogenous variable.
 summary(results_lin_iv)


## 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,
                               trend          = 0,
                               confint        = 1.96,
                               hor            = 20)


# Show all responses
 plot(results_lin_iv)

# Show diagnostics. The first element shows the reaction of the first endogenous variable.
 summary(results_lin_iv)


##############################################################################
#####                         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 2SLS
 results_lin_iv <- lp_lin_iv(endog_data,
                            lags_endog_lin = 4,
                            shock          = shock,
                            instrum        = instrum,
                            use_twosls     = TRUE,
                            trend          = 0,
                            confint        = 1.96,
                            hor            = 20)

# Show all responses
 plot(results_lin_iv)

lpirfs documentation built on March 24, 2021, 1:10 a.m.