IRF {BGVAR}R Documentation

Impulse Response Function

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(gvar.obj, shockc = NULL, nhor = 24,  sign.constr = NA,rotSpec=NULL,cpu=1,full.post=FALSE)

Arguments

gvar.obj

An objected fitted by function bgvar.

shockc

This is a list object. It should contain an entry labelled shock that contains the name of the variable to be shocked. Also it should contain a list entry labelled ccode 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 labelled ident that is either col if the shock is based on a cholesky identification 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.

nhor

Forecasting horizon.

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.

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

    • restrictions This 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 Character vector of length of set of restrictions + 1, specifying the signs to impose. Use either > or <. 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. If specified then the shock will be calibrated to match scal on impact.

  • shock2 Define a second list with the same entries as above to identify a second shock. Can be used iteratively to identify multiple shocks.

rotSpec

Only needed for sign restrictions. Is a list with two entries, Srots specifying for how many rotation matrices that fulfill the restrictions we look for for each posterior draw. In case there are multiple rotation matrices found for a parameter draw, the algorithm proposed by Fry and Pagan (2011) is used to discriminate among the matrices. Default setting is 1. The second entry, MaxTries corresponds 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 for that specific posterior draw to NA and starts looking for a rotation matrix that fulfills the restrictions for the next posterior draw.

cpu

Number of cpu cores for use of parallel computing using the foreach and doParallel packages. This option is recommended when working with sign restrictions to seed up computations. Default is cpu=1 and thus no parallelization.

full.post

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

Value

Author(s)

Martin Feldkircher and Florian Huber

References

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

See Also

See also eerData for an example with sign restrictions.

Examples

 # First example, a US monetary policy shock, quarterly data
 library(BGVAR)
 data(eerData)
  model.ssvs.eer<-bgvar(Data=eer.data,W=W.trade0012,saves=100,burns=100,plag=1,Cpu=1,prior="SSVS",save_thin=1,eigen=TRUE, trim=1.05)
  # US monetary policy shock
  shocks<-list();shocks$shock="stir";shocks$ccode<-"US";shocks$ident="chol";shocks$scal=-100
  irf.chol.us.mp<-IRF(gvar.obj=model.ssvs.eer,shockc=shocks,nhor=48)

  # plots an impulse response function
  irf.plot(irf.chol.us.mp,resp="US.y")

 # calculates generalized impulse response functions for the same shock as above
  shocks$ident="GIRF"
  irf.girf.ssvs<-IRF(gvar.obj=model.ssvs.eer,shockc=shocks,nhor=48)
  irf.plot(irf.girf.ssvs,resp="US.y")

# Shock to first ordered variable yields same responses of cholesky and GIRF
  shocks<-list();shocks$shock="y";shocks$ccode<-"US";shocks$ident="chol";shocks$scal=+1
  irf.chol<-IRF(model.ssvs.eer,shockc=shocks,nhor=48)
  shocks$ident<-"GIRF"
  irf.girf<-IRF(model.ssvs.eer,shockc=shocks,nhor=48)
  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="")


  # second example, cross-country restrictions, multiple shocks and ECB country model
  library(BGVAR)
  data(monthlyData2);new.data2$OC<-NULL
  # estimates the model
  model.ssvs<-bgvar(Data=new.data2,W=W,saves=100,burns=100,plag=1,Cpu=1,prior="SSVS",save_thin=1,eigen=TRUE,trim=1.05,ea.weights=EA.weights)

  EA_countries <- c("AT", "BE", "DE","ES", "FI","FR", "IE", "IT", "NL", "PT","GR","SK") #,"MT","CY","EE","LT","LV")

  # 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$shock="ltir";shocks$ccode<-EA_countries;shocks$ident="chol";shocks$scal=-100
  irf.chol.ssvs<-IRF(gvar.obj=model.ssvs,shockc=shocks,nhor=48)

  # imposes sign restrictions on the cross-section and for a global shock (long-term interest rates)
  sign.constr<-list()
  sign.constr$shock1$shock<-c(paste0(EA_countries[-c(3,12)],".ltir")) # the variable to shock, can be imposed for more than one country
                                                                      #but should be the same variable   for all of them
  sign.constr$shock1$restrictions$res1<-paste0(EA_countries,".y") # restrictions (industrial production should decrease for selected countries)
  sign.constr$shock1$restrictions$res2<-paste0(EA_countries,".p") # another set of restrictions (inflation  should decrease for selected countries)
  sign.constr$shock1$sign<-c(">","<","<") # first entry is for the shock, following entries for the restrictions (ltir should go up, y and p go down)
  sign.constr$shock1$rest.horz<-c(1,1,1) # nr. of time periods restrictions are imposed, first entry is for the shock, following entries for the restrictions
  sign.constr$shock1$constr<-c(1,0.5,0.5) # 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$scal=-100 # a minus 100 bp shock to long-term interest rates (on average)
    rotSpec<-list();rotSpec$MaxTries<-200;rotSpec$Srots<-1
    irf.sign.ssvs<-IRF(gvar.obj=model.ssvs,shockc=NULL,nhor=48,rotSpec=rotSpec,sign.constr=sign.constr)


 # 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$shock="ltir";shocks$ccode<-EA_countries;shocks$ident="chol";shocks$scal=-100
  irf.chol.ssvs<-IRF(gvar.obj=model.ssvs,shockc=shocks,nhor=48)

  # 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
  sign.constr$shock1$restrictions$res1<-paste0(EA_countries,".y") # restrictions (industrial production should decrease for selected countries)
  sign.constr$shock1$restrictions$res2<-paste0(EA_countries,".p") # another set of restrictions (inflation  should decrease for selected countries)
  sign.constr$shock1$sign<-c(">","<","<") # first entry is for the shock, following entries for the restrictions (ltir should go up, y and p go down)
  sign.constr$shock1$rest.horz<-c(2,2,1) # nr. of time periods restrictions are imposed, first entry is for the shock, following entries for the restrictions
  sign.constr$shock1$constr<-c(1,0.5,0.5) # 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$scal=-100 # a minus 100 bp shock to long-term interest rates (on average)
    rotSpec<-list();rotSpec$MaxTries<-200;rotSpec$Srots<-1
    irf.sign.ssvs<-IRF(gvar.obj=model.ssvs,shockc=NULL,nhor=48,rotSpec=rotSpec,sign.constr=sign.constr)





[Package BGVAR version 1.1.3 Index]