I am trying to generate the IFRs related to shock to my third variable (debt) on the other variables in particular the first one.
I have tried few things but seems to get all other shocks.
Any help/advice please?
Thanks,
ozey
Code: Select all
system(model=varmodel)
variables inf govcons debt gdp rir
lags 1 to lags 2
det constant tot{0 2}
end(system)
compute implabel = || $
"Inflation",$
"Govcons",$
"debt",$
"gdp",$
"rir"||
******************************************************************
estimate
compute nvar =%nvar
compute fxx =%decomp(%xx)
compute fwish =%decomp(inv(%nobs*%sigma))
compute wishdof=%nobs-%nreg
compute betaols=%modelgetcoeffs(varmodel)
*
* On the odd values for draws, a draw is made from the inverse Wishart
* distribution for the covariance matrix. This assumes use of the Jeffrey's prior
* |S|**-(n+1)/2 where n is the number of equations in the VAR. The posterior for
* S with that prior is inv(S)~Wishart with T-p d.f. (p = number of explanatory
* variables per equation) and covariance matrix inv(T(S-hat)).
*
declare vect[rect] responses(nkeep)
declare rect[series] impulses(nvar,nvar)
infobox(action=define,progress,lower=1,upper=nkeep) "Monte Carlo Integration"
do draws = 1,nkeep
if %clock(draws,2)==1 {
compute sigmad =%ranwisharti(fwish,wishdof)
compute fsigma =%decomp(sigmad)
compute betau =%ranmvkron(fsigma,fxx)
compute betadraw=betaols+betau
}
else
compute betadraw=betaols-betau
compute %modelsetcoeffs(varmodel,betadraw)
impulse(noprint,model=varmodel,factor=fsigma,results=impulses,steps=nstep)
*
* Store the impulse responses
*
dim responses(draws)(nvar*nvar,nstep)
ewise responses(draws)(i,j)=impulses((i-1)/nvar+1,%clock(i,nvar))(j)
infobox(current=draws)
end do draws
dec vect[strings] xlabel(nvar) ylabel(nvar)
dec vect[integer] depvars
compute depvars=%modeldepvars(varmodel)
do i=1,nvar
compute ll=%l(depvars(i))
compute xlabel(i)=ll
compute ylabel(i)=ll
end do i
infobox(action=remove)
grparm(bold) hlabel 18 matrixlabels 14
grparm axislabel 24
*spgraph(header="Impulse responses",xpos=both,xlab=xlabel, $
*ylab=ylabel,vlab="Responses of",vfields=nvar,hfields=nvar)
*
* Because we want a common scale for all responses of a single variable, we need
* to do all the calculations for a full row of graphs first. Note, by the way,
* that this graph transposes rows and columns from the arrangement used in the
* original montevar.
*
dec vect[series] upper(nvar) lower(nvar) resp(nvar)
do i=1,nvar
compute header="plot of responses of "+implabel(i)
compute minlower=maxupper=0.0
smpl 1 nkeep
do j=1,nvar
clear lower(j) upper(j) resp(j)
do k=1,nstep
set work 1 nkeep = responses(t)((i-1)*nvar+j,k)
compute frac=%fractiles(work,||.5,.95||)
compute lower(j)(k)=frac(1)
compute upper(j)(k)=frac(2)
compute resp(j)(k)=%avg(work)
end do k
compute maxupper=%max(maxupper,%maxvalue(upper(j)))
compute minlower=%min(minlower,%minvalue(lower(j)))
end do j
*
smpl 1 nstep
do j=1,nvar
graph(header=header,klabels=implabel,ticks,min=minlower,max=maxupper,number=0) 3 j i
# resp(j) /8
# upper(j) / 6
# lower(j) / 6
*end do j
end do i
*
*
*spgraph(done