How to code up BVAR Impulse Response???

Questions and discussions on Vector Autoregressions
dnfloro1
Posts: 9
Joined: Wed Sep 25, 2013 8:32 am

How to code up BVAR Impulse Response???

Unread post by dnfloro1 »

Hi Tom,

My question is a bit basic, as I dont know how to code up the IMPULSE from the BVAR code in the Bayesian Econometrics Workbook. The code below does forecasting.
Im a newbie in Bayesian VAR, so thanks for your patience and help!

FROM THE BAYESIAN COURSE WORKBOOK:

Code: Select all

compute lags=4			;*Number of lags
compute nstep=16		;*Number of response steps
compute nburn=500   	;*Number of burn-in draws
compute ndraws=2500	;*Number of keeper draws
*
open data haversample.rat
cal(q) 1959
data(format=rats) 1959:1 2006:4 ftb3 gdph ih cbhm
*
set loggdp = log(gdph)
set loginv = log(ih)
set logc   = log(cbhm)
*
* These are the controlling parameters for the symmetric "Minnesota"
* prior - the own lag tightness and the relative tightness on the other
* lags.
*
compute tight=.1
compute other=.5
*
* First, estimate the system with a prior via mixed estimation, to see if
* we come up with something similar via Gibbs sampling.
*
system(model=varmodel)
variables loggdp loginv logc ftb3
lags 1 to lags
specify(type=symmetric,tight=tight) other
det constant
end(system)
************************************************************************************
*
* Estimate with a prior
*
estimate
compute nvar=%nvar
*
@BVARBuildPriorMN(model=varmodel,tight=.1,other=.5) hbpriors hpriors
@BVARFinishPrior hbpriors hpriors bprior hprior
*
compute sigmad=%sigma
*
dec vect[series] forecast(nvar)
dec vect[series] forestderr(nvar)
*
* Range to forecast
*
compute fstart=%regend()+1
compute fend  =fstart+nstep-1
*
do i=1,nvar
   set forecast(i)   fstart fend = 0.0
   set forestderr(i) fstart fend = 0.0
end do i
*
infobox(action=define,progress,lower=-nburn,upper=ndraws) "Gibbs Sampler"
do draw=-nburn,ndraws
   infobox(current=draw)
   *
   * Draw b given sigma
   *
   compute bdraw =%ranmvkroncmom(%cmom,inv(sigmad),hprior,bprior)
   compute rssmat=%sigmacmom(%cmom,bdraw)
   *
   * Draw sigma given b
   *
   compute sigmad=%ranwisharti(%decomp(inv(rssmat)),%nobs)
   if draw<=0
      next

   compute %modelsetcoeffs(varmodel,bdraw)
   simulate(model=varmodel,cv=sigmad,results=simresults,steps=nstep)
   do i=1,nvar
      set forecast(i)   fstart fend = forecast(i)+simresults(i)
      set forestderr(i) fstart fend = forestderr(i)+simresults(i)**2
   end do i
end do draw
infobox(action=remove)
*
do i=1,nvar
   set forecast(i) fstart fend   = forecast(i)/ndraws
   set forestderr(i) fstart fend = sqrt(forestderr(i)/ndraws-forecast(i)**2)
end do i
*
do i=1,nvar
   set lower fstart fend = forecast(i)-2.0*forestderr(i)
   set upper fstart fend = forecast(i)+2.0*forestderr(i)
   graph(header="Forecasts of "+%l(%modeldepvars(varmodel)(i))) 4
   # forecast(i) fstart fend
   # lower fstart fend 2
   # upper fstart fend 2
   # %modeldepvars(varmodel)(i) fstart-12 fstart-1
end do i
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: How to code up BVAR Impulse Response???

Unread post by TomDoan »

There are literally dozens of examples that do the impulse responses of various forms of VAR's. We did the forecasts in that example because we didn't have many examples of how to handle forecasts.

Look at the MONTEVAR.RPF example. Everything after the %MODELSETCOEFFS instruction in MONTEVAR is for handling impulse responses, and everything after that in the program you posted is for handling forecasts.
mightydell37
Posts: 17
Joined: Fri Oct 10, 2014 2:13 am

Re: How to code up BVAR Impulse Response???

Unread post by mightydell37 »

TomDoan wrote:There are literally dozens of examples that do the impulse responses of various forms of VAR's. We did the forecasts in that example because we didn't have many examples of how to handle forecasts.

Look at the MONTEVAR.RPF example. Everything after the %MODELSETCOEFFS instruction in MONTEVAR is for handling impulse responses, and everything after that in the program you posted is for handling forecasts.
Can I use @MONTEVAR procedure after estimating the BVAR?
Post Reply