They "repeat a draw if the residuals extracted make the GIRF explosive". So a GIRF is considered explosive if the last step ahead of the considered shock variable takes values which are extreme. In their example it is 10 standard deviations of the structural shock. I included this into the ZLB GIRF code. but I also made some additions/changes. I also discard values which make the first step ahead of the shock variable extremely large. My threshold value for this is 5 standrard deviations. Moreover since the Gauss-Seidel-Algorithm within the FORECAST instruction produces an error whenever there is an explosive draw, which would stop the entire loop, I use ENV TRAPERRORS before the Bootstrap. This should prevent the loop from breaking. After the loop continues the draw is repeated. Here is my code for the ZLB part:
Code: Select all
***********
*** ZLB ***
***********
do i = 1,nvar
set girf(i) hstart hend = 0.0
set girfzlb(i) hstart hend = 0.0
end do i
env traperrors
compute nhist = 0
do hist = zlbstart, zlbend
do k=0, nlag-1
compute VIX(hstart-nlag+k) = VIXraw(hist-nlag+k) ;* Pulls the history and sets its values into the following range: Lag periods before hstart to one period before hstart, such that hstart is the first forecasting period
compute lnP(hstart-nlag+k) = lnPraw(hist-nlag+k)
compute lnGDP(hstart-nlag+k) = lnGDPraw(hist-nlag+k)
compute lnINV(hstart-nlag+k) = lnINVraw(hist-nlag+k)
compute lnCons(hstart-nlag+k) = lnConsraw(hist-nlag+k)
compute FFR(hstart-nlag+k) = FFRraw(hist-nlag+k)
compute interact(hstart-nlag+k) = interactraw(hist-nlag+k)
end do k
compute countrep = 0 ;* to count for repetitions in the draws
do draw=1,ndraws
*************************************************************
*** Draw random entries for residuals for forecast period ***
*************************************************************
:newtry
if countrep == ndraws{
compute nhist=nhist-1
break
}
boot entries hstart hend bstart bend ;*draws residuals from the whole range and puts them in the range hstart to hend for loading the forecast
do z=1,nvar
set xpath(z) hstart hend = u(z)(entries(t))
end do z
***********************************************************************************
*** Simulate the path y_(t+h) by loading the VAR with the bootstraped residuals ***
***********************************************************************************
forecast(model=fullmodel,from=hstart,to=hend,results=base,paths,noprint) ;* Forecasts values from hstart to hend and loads the forecast with the shocks
# xpath(1) xpath(2) xpath(3) xpath(4) xpath(5) xpath(6)
***************************************************************************************************************************
*** Simulate the path y_(t+h) by loading the VAR with shocks where the first period is the structural uncertainty shock ***
***************************************************************************************************************************
@structresids(factor=chol) xpath hstart hstart vimp
*compute delta = 1/(chol(1,1))
compute delta = 1
compute vimp(1)(hstart) = vimp(1)(hstart)+delta
@structresids(factor=invchol) vimp hstart hstart xpathpert
do j =1, nvar
compute xpath(j)(hstart) = xpathpert(j)(hstart)
end do j
forecast(model=fullmodel,from=hstart,to=hend,results=wshock,paths,noprint)
# xpath(1) xpath(2) xpath(3) xpath(4) xpath(5) xpath(6)
*********************************
*** Check for explosive IRFs ***
*********************************
compute nexpl = 0
compute test1 = wshock(1)(hend)-base(1)(hend)
compute test2 = wshock(1)(hstart)-base(1)(hstart)
if test1>=chol(1,1)*10*abs(delta).OR.test1<=(-1)*chol(1,1)*10*abs(delta).OR.test2>=chol(1,1)*5*abs(delta)
compute nexpl = nexpl+1
if nexpl>0{
compute countrep = countrep + 1
goto newtry
}
******************************************************
*** Accumulate GIRFs to calculate average later on ***
******************************************************
do i = 1, nvar
set girf(i) hstart hend = girf(i) + (wshock(i)-base(i))
end do i
end do draw
do i = 1, nvar
set girf(i) hstart hend = girf(i)/ndraws
set girfzlb(i) hstart hend = girfzlb(i) + girf(i)
end do i
compute nhist = nhist+1
end do hist
env notraperrors
do i = 1,nvar
set girfzlb(i) hstart hend = girfzlb(i)/nhist
end do i
spgraph(vfields=2,hfields=3)
do i = 1, nvar
graph(number = 0,header = irflabels(i), key=loright) 2
# girfnormal(i) hstart hend-1
# girfzlb(i) hstart hend-1
end do i
spgraph(done)
Whats you opinion about the code? Do you have any further suggestions?
In general is there another way to force the loop to continue after an error occured, different from ENV TTRAPERRORS?
Thank you
best Jules