BQDoDraws for more than 2 variables

Questions and discussions on Vector Autoregressions
ursula
Posts: 4
Joined: Tue Jun 30, 2009 10:27 pm

BQDoDraws for more than 2 variables

Unread post by ursula »

Hello. I've been trying to adapt the BQDoDraw procedure for 4 variables and even though I've tried over and over, when I run it with MCFEVD, the graph that appears has only the OY axis and the rest is empty. I really don't understand what's going on, there is no message error so I have no clu what's going on. I suspect it may be the "accumulate" option in the BQDoDraw, maybe I haven't modified it properly.
Help would be greatly appreciated, especially since time is rather short.
Thank you very much.

This is the procedure:
option model model
option integer draws 1000
option integer steps 24
option vect[int] accum ||1, 2, 3, 4||

*
local integer nvar
local rect fxx fwish fsigmad factor
local integer wishdof
local rect betaols betau betadraw
local symm sigmad
local integer i j draw
*
compute fxx =%decomp(%xx)
compute fwish =%decomp(inv(%nobs*%sigma))
compute wishdof=%nobs-%nreg
compute betaols=%modelgetcoeffs(model)
*
local rect[series] impulses(nvar,nvar)
*
declare vect[rect] %%responses(draws)
*
infobox(action=define,progress,lower=1,upper=draws) "Monte Carlo Integration"
do draw=1,draws
if %clock(draw,2)==1 {
compute sigmad =%ranwisharti(fwish,wishdof)
compute fsigmad =%decomp(sigmad)
compute betau =%ranmvkron(fsigmad,fxx)
compute betadraw=betaols+betau
}
else
compute betadraw=betaols-betau
compute %modelsetcoeffs(model,betadraw)
*
compute factor=%bqfactor(sigmad,%modellagsums(model))
*
impulse(noprint,model=model,factor=factor,results=impulses,steps=steps)
do i=1,%rows(accum)
acc impulses(accum(i),1) 1 steps
acc impulses(accum(i),2) 1 steps
acc impulses(accum(i),3) 1 steps
acc impulses(accum(i),4) 1 steps

end do i
dim %%responses(draw)(nvar*nvar,steps)
ewise %%responses(draw)(i,j)=impulses((i-1)/nvar+1,%clock(i,nvar))(j)
infobox(current=draw)
end do draw
infobox(action=remove)
compute %modelsetcoeffs(model,betaols)
*
end BQDoDraws_4

And this is my program:

calendar(q) 1998:3
allocate 2008:3
open data D:\date
data(format=xls, org=columns) / dlgdp dlgov dlcpi lrer
set difgdp = dlgdp - dlgdp{1}
set difrer = lrer-lrer{1}
print
system(model=rervar)
variables dlgov difgdp difrer dlcpi
lags 1 to 2
det constant
end(system)
estimate(residuals=resids, coefficients=coeff) 1998:4 2008:3
display coeff

compute [vect[strings]] shocklabels=||"1","2","3","4"||
compute [vect[strings]] vlabels=||"a","b","c","d"||

source D:\BQDoDraws_4
@BQDoDraws_4(model=rervar)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: BQDoDraws for more than 2 variables

Unread post by TomDoan »

Your adjustment looks fine. You didn't include any of the post-processing (MCFEVDTable or whatever), so it's hard to tell what might happen when you do that.
ursula
Posts: 4
Joined: Tue Jun 30, 2009 10:27 pm

Re: BQDoDraws for more than 2 variables

Unread post by ursula »

Thank you for your prompt reply. I didn't include the rest because I was convinced there was something wrong with the adjustment and because it's straightdforward, the next line was the MCGraphIRF procedure. So the final lines of the program are

compute [vect[strings]] shocklabels=||"1","2","3","4"||
compute [vect[strings]] vlabels=||"a","b","c","d"||

source D:\BQDoDraws_4
@BQDoDraws_4(model=rervar)

source D:\bqextras\MCGraphIRF
@MCGraphIRF(model=rervar,shocklabels=shocklabels,varlabels=vlabels,include=||3||). Here I have only the OY axis displayed, nothing else.

disp "Table 2-Variance Decomposition of the Real exchange rate"
@MCFEVDTable(model=varmodel,horizons=||1,2,3,4,8,12,24||,$
varlabels=vlabels,shocklabels=shocklabels,table=byvariables)

When I run the MCFEVDTable procedure, invariably I have the error: "WinRats 32 has encountered a problem and needs to close".
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: BQDoDraws for more than 2 variables

Unread post by TomDoan »

Please send a copy of the data file to support@estima.com so we can run this and see what's happening.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: BQDoDraws for more than 2 variables

Unread post by TomDoan »

This corrects the original procedure. The compute nvar=... line was missing. I also changed the ACC instructions that accumulate the responses to get the integrated effects into a loop so this can be used for model sizes other than 4.

Updated 2 May 2013 from original post from 2009. Corrects order in which responses are saved to match those now used by (for instance) @MCGraphIRF.

Code: Select all

procedure BQDoDraws_4
*
option model model
option integer draws 1000
option integer steps 24
option vect[int] accum ||1, 2, 3, 4||
*
local integer nvar
local rect fxx fwish fsigmad factor
local integer wishdof
local rect betaols betau betadraw
local symm sigmad
local vect   ix
local integer i j draw
*
* This line was missing
*
compute nvar=%modelsize(model)
*
compute fxx =%decomp(%xx)
compute fwish =%decomp(inv(%nobs*%sigma))
compute wishdof=%nobs-%nreg
compute betaols=%modelgetcoeffs(model)
*
local rect[series] impulses(nvar,nvar)
*
declare vect[rect] %%responses(draws)
*
infobox(action=define,progress,lower=1,upper=draws) "Monte Carlo Integration"
do draw=1,draws
if %clock(draw,2)==1 {
compute sigmad =%ranwisharti(fwish,wishdof)
compute fsigmad =%decomp(sigmad)
compute betau =%ranmvkron(fsigmad,fxx)
compute betadraw=betaols+betau
}
else
compute betadraw=betaols-betau
compute %modelsetcoeffs(model,betadraw)
*
compute factor=%bqfactor(sigmad,%modellagsums(model))
*
impulse(noprint,model=model,factor=factor,results=impulses,steps=steps)
do i=1,%rows(accum)
   do j=1,nvar
      acc impulses(accum(i),j) 1 steps
   end do j
end do i
dim %%responses(draw)(nvar*nvar,steps)
ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
infobox(current=draw)
end do draw
infobox(action=remove)
compute %modelsetcoeffs(model,betaols)
*
end BQDoDraws_4


Last bumped by TomDoan on Thu May 02, 2013 11:18 am.
Post Reply