3
$\begingroup$

I have two questions on how to produce impulse responses using R

(1) Impulse responses to a negative shock in the independent variable (money supply)

(2) Impulse responses at 2 standard deviations

The code I used to generate the impulse responses to a positive shock at 1 standard deviation is the following:

m1 <- read.csv("m1.csv", header=T)

m1

varm1 <- VAR(m1, p=8, type="cons")

irfm1 <- irf(varm1, impulse="m1", response= c("gdp"), boot = FALSE)

plot(irfm1)

irfm1
$\endgroup$
3
$\begingroup$

Here is a simple example that should work:

library(vars)
data("Canada")
var.2c=VAR(Canada,p=2,type="const")
# 1 SD impulse reponse function
irf.rw.e=irf(var.2c,impulse="rw",response=c("e"))
# gamma is the number of standard deviations for the irf
gamma=-0.25
irf.rw.e_gamma = irf.rw.e
n=length(irf.rw.e_gamma$irf$rw)
for(i in 1:n){
    irf.rw.e_gamma$irf$rw[i]   = irf.rw.e_gamma$irf$rw[i]*gamma
    irf.rw.e_gamma$Lower$rw[i] = irf.rw.e_gamma$Lower$rw[i]*gamma
    irf.rw.e_gamma$Upper$rw[i] = irf.rw.e_gamma$Upper$rw[i]*gamma
} 
plot(irf.rw.e)
plot(irf.rw.e_gamma)

Source

| improve this answer | |
$\endgroup$
  • $\begingroup$ in the example above (original question) it is for a positive standard deviation shock. Any idea on how to code a negative 0.25% shock to the policy indicator? $\endgroup$ – Rollo99 Feb 28 at 10:27
  • 1
    $\begingroup$ I tweaked the code so that it could make an IRF for an arbitrary size and sign inpulse. The object irf.rw.e holds the basic 1 std dev positive irf, and irf.rw.e_gamma holds the irf for the a shock of gamma standard deviations. So if you want it to be -0.25, set gamma=-0.25. I also patched an issue where the confidence intervals may not be correct. This matches the confidence intervals to size of the shock (bigger shocks, bigger bounds). $\endgroup$ – BKay Feb 28 at 11:44
  • $\begingroup$ thanks so much! Super super helpful, can't give you more points on the solution as I already gave you all on the previous one. Thanks a lot again $\endgroup$ – Rollo99 Feb 28 at 11:45
  • $\begingroup$ do you know how to do the same but using externalinstrument? I can post a question. I have already posted one on stackoverflow here $\endgroup$ – Rollo99 Mar 12 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.