Learn R Programming

BGVAR (version 2.0.1)

IRF: Impulse Response Functions

Description

This function calculates three alternative ways of dynamic responses, namely generalized impulse response functions (GIRFs) as in Pesaran and Shin (1998), orthogonalized impulse response functions using a Cholesky decomposition and finally impulse response functions given a set of user-specified sign restrictions.

Usage

IRF(obj, nhor=24, shock=NULL, sign.constr=NULL, save.store=FALSE, multithread=FALSE, 
           verbose=TRUE)

Arguments

obj

an object of class bgvar.

nhor

forecasting horizon.

shock

This is a list object. It should contain an entry labeled var that contains the name of the variable to be shocked. Also it should contain a list entry labeled cN that contains a character (or character vector) of the country (countries) in which the variable should be shocked. Finally it has to contain an entry labeled ident that is either chol if the shock is based on a short-run identification scheme done with the Cholesky decomposition or girf if generalized impulse responses should be calculated. In case impulses should be normalized (e.g., a +100bp increase in the interest rate), add another entry scal that contains a numeric value of the desired impact normalization.

sign.constr

the user should submit a list containing the following entries

  • shock1 is a list object that defines sign restrictions for a particular shock.

    • shockvar is a character vector containing the country and variable to shock separated by a dot. Example, "AT.ltir" (long-term interest rates in Austria).

    • restrictions is a list containing the variables to restrict. Can have several sub-list restrictions, e.g., sign.constr$shock1$restricionts$rest1=c("DE.y","AT.y"), sign.constr$shock1$restricionts$rest2=c("NL.p","AT.p"), putting restrictions on GDP in Germany and Austria and a second set of restrictions on prices in the Netherlands and Austria.

    • sign is a character vector of length of set of restrictions + 1, specifying the signs to impose. Use either >, < or 0. The latter implements zero restrictions according to Arias et al. (2019). First entry is for the shock, say AT.ltir should go up, the following entries refer to the restrictions. sign.constr$shock1$sign=c(">", "<", "<") would impose AT.ltir to increase, and variables specified in sign.constr$shock1$restricionts$rest1 and sign.constr$shock1$restricionts$rest2 to decrease.

    • rest.horz is a vector with same length as slot sign above and specifies the length of periods the restrictions are imposed. If rest.horz is 1, only impact restrictions are considered.

    • constr is a vector with same length as slot sign above with elements lying between 0 and 1. It specifies the percentage of countries for which cross-country restrictions have to hold. If no cross-country restrictions are supplied, set all elements of constr to 1.

    • scal optional numeric in case impact normalization is desired.

    #' MaxTries Optional numeric corresponding to the maximum tries to search for a rotation matrix that fulfills the user-specified restrictions. Default is set to 7500. After MaxTries unsuccessful tries the algorithm sets the impulse response for that specific posterior draw to NA. shock2 define a second list with the same arguments as shock1 to identify a second shock. Can be used iteratively to identify multiple shocks.

save.store

If set to TRUE the full posterior is returned. Default is set to FALSE in order to save storage.

multithread

If set to TRUE parallel computing using the packages foreach and doParallel. Number of cores is set to maximum number of cores in the computer. This option is recommended when working with sign restrictions to speed up computations. Default is set to FALSE and thus no parallelization.

verbose

If set to FALSE it suppresses printing messages to the console.

Value

Returns a list of class bgvar.irf with the following elements:

  • posterior is a four-dimensional array (K times nhor times nr. of shocks times 7) that contains 7 quantiles of the posterior distribution of the impulse response functions: the 50% ("low25" and "high75"), the 68% ("low16" and "high84") and the 90% ("low05" and "high95") credible sets along with the posterior median ("median").

  • rot.nr in case identification is based on sign restrictions (i.e., ident="sign"), this provides the number of rotation matrices found for the number of posterior draws (save*save_thin).

  • shock in case identification is based on Cholesky decomposition (i.e. ident="chol"), this gives back the details of the identification specification.

  • sign.constr in case identification is based on sign restrictions (i.e. ident="sign"), this gives back the set of sign restrictions specified by the user.

  • ident character giving back the chosen identification scheme.

  • struc.obj is a list object that contains posterior quantitites needed when calculating historical decomposition and structural errors via hd.decomp.

    • A median posterior of global coefficient matrix.

    • Ginv median posterior of matrix Ginv, which describes contemporaneous relationships between countries.

    • S posterior median of matrix with country variance-covariance matrices on the main diagonal.

    • Rmed posterior rotation matrix if ident="sign".

  • model.obj is a list object that contains model-specific information, in particular

    • xglobal used data of the model.

    • plag used lag specification of the model.

  • IRF_store is a four-dimensional array (K times nhor times nr. of shock times saves) which stores the whole posterior distribution. Exists only if save.irf.store=TRUE.

References

Arias, J.E., Rubio-Ramirez, J.F, and D.F. Waggoner (2018) Inference Based on SVARs Identified with Sign and Zero Restrictions: Theory and Applications. Econometrica Vol. 86(2), pp. 685-720.

D'Amico, S. and T. B. King (2017) What Does Anticipated Monetary Policy Do? Federal Reserve Bank of Chicago Working paper series, Nr. 2015-10.

Pesaran, H.M. and Y. Shin (1998) Generalized impulse response analysis in linear multivariate models. Economics Letters, Volume 58, Issue 1, p. 17-29.

Examples

Run this code
# NOT RUN {
oldpar <- par(no.readonly =TRUE)
# First example, a US monetary policy shock, quarterly data
library(BGVAR)
data(eerData)
model.ssvs.eer<-bgvar(Data=eerData,W=W.trade0012,saves=100,burns=100,plag=1,prior="SSVS",
                      eigen=TRUE)
# US monetary policy shock
shocks<-list();shocks$var="stir";shocks$cN<-"US";shocks$ident="chol";shocks$scal=-100
irf.chol.us.mp<-IRF(obj=model.ssvs.eer,shock=shocks,nhor=24)
# plots an impulse response function
plot(irf.chol.us.mp,resp="US")

# calculates generalized impulse response functions for the same shock as above
shocks$ident="girf"
irf.girf.ssvs<-IRF(obj=model.ssvs.eer,shock=shocks,nhor=24)
plot(irf.girf.ssvs,resp="US.y")
# Shock to first ordered variable yields same responses of Cholesky and GIRF
shocks<-list();shocks$var="y";shocks$cN<-"US";shocks$ident="chol";shocks$scal<--100
irf.chol<-IRF(model.ssvs.eer,shock=shocks,nhor=24)
shocks$ident<-"girf"
irf.girf<-IRF(model.ssvs.eer,shock=shocks,nhor=24)
matplot(cbind(irf.chol$posterior["US.y",,1,"median"],
              irf.girf$posterior["US.y",,1,"median"]),
        type="l",ylab="")
matplot(cbind(irf.chol$posterior["US.Dp",,1,"median"],
              irf.girf$posterior["US.Dp",,1,"median"]),
        type="l",ylab="")
matplot(cbind(irf.chol$posterior["EA.y",,1,"median"],
              irf.girf$posterior["EA.y",,1,"median"]),
        type="l",ylab="")

sign.constr<-list()
# the variable to shock, can be imposed for more than one country
sign.constr$shock1$shock<-c("US.stir") 
# but should be the same variable for all of them 
sign.constr$shock1$restrictions$res1<-c("US.y")
sign.constr$shock1$restrictions$res2<-c("US.Dp")
# first entry is for the shock, following entries for the restrictions 
# (ltir should go up, y and p go down)
sign.constr$shock1$sign<-c(">","<","<")
# nr. of time periods restrictions are imposed, first entry is for the shock, 
# following entries for the restrictions 
sign.constr$shock1$rest.horz<-c(1,1,1) 
# are constraints binding for all (1) countries specified for 
# at least 50\% of the countries (0.5), or 75\% (0.75)
sign.constr$shock1$constr<-c(1,1,1) 
# a minus 100 bp shock to long-term interest rates (on average)
sign.constr$shock1$scal=+100 
sign.constr$MaxTries<-200
irf.sign.us.mp<-IRF(obj=model.ssvs.eer,sign.constr=sign.constr,nhor=24)
plot(irf.sign.us.mp,resp=c("US"))

# second example, cross-country restrictions, multiple shocks and ECB country model
data(monthlyData);monthlyData$OC<-NULL
OE.weights <- list(EB=EA.weights)
model.ssvs<-bgvar(Data=monthlyData,W=W,saves=100,burns=100,plag=1,prior="SSVS",
                  thin=1,eigen=TRUE,OE.weights=OE.weights)
EA_countries <- c("AT", "BE", "DE","ES", "FI","FR", "IE", "IT", "NL", "PT","GR","SK")
# A simultaneous Cholesky shock to long-term interest rates in the euro area countries, 
# scaled to amount to -100 basis points (on average over the EA countries).
# Note that the ordering of the variables influences the response, the ordering is exactly as 
# in the country models, to use a different order you have re-estimate the model (by bgvar)
shocks<-list();shocks$var="ltir";shocks$cN<-EA_countries;shocks$ident="chol";shocks$scal=-100
irf.chol.ssvs<-IRF(obj=model.ssvs,shock=shocks,nhor=48)
plot(irf.chol.ssvs,resp=c("AT"))
# imposes sign restrictions on the cross-section and for a global shock (long-term interest rates)
sign.constr<-list()
# the variable to shock, can be imposed for more than one country
sign.constr$shock1$shock<-c(paste(EA_countries[-c(3,12)],".ltir",sep="")) 
# but should be the same variable for all of them
# restrictions (industrial production should decrease for selected countries)
sign.constr$shock1$restrictions$res1<-paste(EA_countries,".y",sep="")
# another set of restrictions (inflation  should decrease for selected countries) 
sign.constr$shock1$restrictions$res2<-paste(EA_countries,".p",sep="")
# first entry is for the shock, following entries for the restrictions 
# (ltir should go up, y and p go down) 
sign.constr$shock1$sign<-c(">","<","<") 
# nr. of time periods restrictions are imposed, first entry is for the shock, 
# following entries for the restrictions
sign.constr$shock1$rest.horz<-c(1,1,1) 
# are constraints binding for all (1) countries specified or for 
# at least 50\% of the countries (0.5), or 75\% (0.75)
sign.constr$shock1$constr<-c(1,0.5,0.5) 
# a minus 100 bp shock to long-term interest rates (on average)
sign.constr$shock1$scal=-100 
sign.constr$MaxTries<-200
irf.sign.ssvs<-IRF(obj=model.ssvs,nhor=48,sign.constr=sign.constr)
plot(irf.sign.ssvs,resp=c("AT"))
 
# Same example but using a local (German) shock and cross-country restrictions.
# Note that the ordering of the variables influences the response, 
# the ordering is exactly as in the country models, to use a different order you have re-estimate
# the model (by bgvar)
shocks<-list();shocks$var="ltir";shocks$cN<-EA_countries;shocks$ident="chol";shocks$scal=-100
irf.chol.ssvs<-IRF(obj=model.ssvs,shock=shocks,nhor=24)
 
# imposes sign restrictions on the cross-section and for a global shock (long-term interest rates)
sign.constr<-list()
sign.constr$shock1$shock<-c("DE.ltir") # the variable to shock, 
# can be imposed for more than one country
#but should be the same variable for all of them
# restrictions (industrial production should decrease for selected countries)
sign.constr$shock1$restrictions$res1<-paste(EA_countries,".y",sep="") 
# another set of restrictions (inflation  should decrease for selected countries)
sign.constr$shock1$restrictions$res2<-paste(EA_countries,".p",sep="")
# first entry is for the shock, following entries for the restrictions 
# (ltir should go up, y and p go down)
sign.constr$shock1$sign<-c(">","<","<") 
# nr. of time periods restrictions are imposed, 
# first entry is for the shock, following entries for the restrictions
sign.constr$shock1$rest.horz<-c(2,2,1) 
# are constraints binding for all (1) countries specified or for 
# at least 50\% of the countries (0.5), or 75\% (0.75)
sign.constr$shock1$constr<-c(1,0.5,0.5) 
# a minus 100 bp shock to long-term interest rates (on average)
sign.constr$shock1$scal=-100
sign.constr$MaxTries<-200
irf.sign.ssvs<-IRF(obj=model.ssvs,nhor=24,sign.constr=sign.constr)
 
# Example with zero restriction (Arias et al., 2018) and 
# rationality conditions (D'Amico and King, 2017).
data("eerDataspf")
model.ssvs.eer<-bgvar(Data=eerDataspf,W=W.trade0012.spf,saves=300,burns=300,
                      plag=1,prior="SSVS",thin=1,eigen=TRUE)
sign.constr<-list()
sign.constr$shock1$shock<-"US.stir_t+4"
sign.constr$shock1$restrictions$res1<-"US.Dp_t+4"
sign.constr$shock1$restrictions$res2<-"US.stir"
sign.constr$shock1$restrictions$res3<-"US.y_t+4"
# rationality condition: US.stir_t+4 on impact is equal to average of
# IRF of US.stir between horizon 1 and 4 (defined with rest.horz, but as period 5!)
sign.constr$shock1$restrictions$res4<-"US.stir_t+4"
# rationality condition: US.Dp_t+4 on impact is equal to H-step ahead IRF of US.Dp in 
# horizon 4 (defined with rest.horz, but as period 5!)
sign.constr$shock1$restrictions$res5<-"US.Dp_t+4"
# rationality condition: US.y_t+4 on impact is equal to H-step ahead IRF of US.y in 
# horizon 4 (defined with rest.horz, but as period 5!)
sign.constr$shock1$restrictions$res6<-"US.y_t+4"
sign.constr$shock1$sign<-c(">","<","0","<","ratio.avg","ratio.H","ratio.H")
sign.constr$shock1$rest.horz<-c(1,1,1,1,5,5,5)
sign.constr$shock1$constr<-c(1,1,1,1,1,1,1)
sign.constr$shock1$scal=0.1
sign.constr$MaxTries<-100
irf.sign<-IRF(obj=model.ssvs.eer,nhor=20,sign.constr=sign.constr)
par(mfrow=c(4,1),mar=c(5.1,4.1,4.1,2.1))
# rationality condition: US.stir_t+4 on impact is equal to average of IRF of 
# US.stir between horizon 1 and 4
matplot(cbind(irf.sign$posterior["US.stir_t+4",,1,"median"],
              irf.sign$posterior["US.stir",,1,"median"]),
        type="l",ylab="",main="stir")
abline(h=mean(irf.sign$posterior["US.stir",2:5,1,"median"]))
abline(v=c(1,5),lty=3,col="grey")
# rationality condition: US.y_t+4 on impact is equal to H-step ahead IRF of US.y in horizon 4
matplot(cbind(irf.sign$posterior["US.y_t+4",,1,"median"],
              irf.sign$posterior["US.y",,1,"median"]),
        type="l",ylab="",main="y")
abline(h=irf.sign$posterior["US.y_t+4",1,1,"median"])
abline(v=5,lty=3,col="grey")
# rationality condition: US.Dp_t+4 on impact is equal to H-step ahead IRF of US.Dp in horizon 4
matplot(cbind(irf.sign$posterior["US.Dp_t+4",,1,"median"],
              irf.sign$posterior["US.Dp",,1,"median"]),
        type="l",ylab="",main="Dp")
abline(h=irf.sign$posterior["US.Dp_t+4",1,1,"median"])
abline(v=5,lty=3,col="grey")
par(mar=rep(0,4))
plot("1",type="n",axes=FALSE)
legend("center",c("expectation","actual"),lty=1:2,col=c("black","red"),bty="n",ncol=2)
par(oldpar)
# }

Run the code above in your browser using DataLab