I tried to adjust the gibbsvar.rpf, with an independent Minnesota-Wishart prior, to do impulse response analysis. I deleted everything, which had to do with forecasting since I am not interested in that. To draw and store the impulse responses within the Gibbs loop I took parts of the codes in Bayesian Econometrics workbook example 6.2. Is this in general the right way to do this task? After the Gibbs sampling I tried to graph the IRFs with confidence bands by using @mcgraphirf. It graphs the IRFs, but no error bands. Why is this the case?
The resulting code is given by:
Code: Select all
*** Data
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)
*** VAR Setup and Storage Matrices
compute lags=4 ;*Number of lags
compute nstep=40 ;*Number of response steps
compute nburn=500 ;*Number of burn-in draws
compute ndraws=2500 ;*Number of keeper draws
compute tight=.1
compute other=.5
system(model=varmodel)
variables loggdp loginv logc ftb3
lags 1 to lags
det constant
end(system)
estimate(ols,sigma) ;*for initial draw of VAR coefficients
impulse(noprint,model=varmodel,steps=nstep,results=impulses) ;*initial set of of impulse responses
compute nvar=%nvar ;* Number of equations estimated
dec vect olssee(nvar)
ewise olssee(i)=sqrt(%sigma(i,i)) ;* standard deviations for rescaling
declare vect[rect] %%responses(ndraws);
declare rect[series] impulses(nvar,nvar)
*** Minnesota Prior
* Create the prior mean and (square root of) precision. The olssee
* values are used to scale the precision. The prior mean is 1 for the
* first own lag in each equation, and 0 otherwise. The constant is given
* a mean of zero with a zero precision (that is, a flat prior).
compute ncoef=lags*nvar+1 ;* Number of coefficients per equation
dec rect minnmean(ncoef,nvar) minnprec(ncoef,nvar)
do i=1,nvar
do j=1,nvar
do l=1,lags
compute minnmean((j-1)*lags+l,i)=(i==j.and.l==1)
compute minnprec((j-1)*lags+l,i)=olssee(j)/olssee(i)*%if(i==j,1.0/tight,1.0/(other*tight))
end do l
end do j
compute minnmean(ncoef,i)=0.0,minnprec(ncoef,i)=0.0
end do i
ewise minnprec(i,j)=minnprec(i,j)^2
compute hprior=%diag(%vec(minnprec))
compute bprior=minnmean
compute sigmad=%sigma
cmom(model=varmodel)
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);* %cmom is the cross moment matrix and is always the same
compute rssmat=%sigmacmom(%cmom,bdraw)
*
* Draw sigma given b
*
compute sigmad=%ranwisharti(%decomp(inv(rssmat)),%nobs)
if draw<=0
next
compute %modelsetcoeffs(varmodel,bdraw)
* Store the impulse responses
*
dim %%responses(draw)(nvar*nvar,nstep)
local vector ix
ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
end do draw
infobox(action=remove)
** Impulse response
@mcgraphirf(model=varmodel,center=median,percentiles=||.10,.90||)
Thank you in advance
Jules