For questions and discussion related to graphs, reports, and other output, including issues related to presenting or publishing results.
Ozmando
Posts: 52
Joined: Sun Jul 15, 2012 4:04 pm

Good day!,
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.
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 betau   =%ranmvkron(fsigma,fxx)
}
else
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
*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
# resp(j)   /8
# upper(j) / 6
# lower(j) / 6
*end do j
end do i
*
*
*spgraph(done``````
TomDoan
Posts: 7536
Joined: Wed Nov 01, 2006 4:36 pm

Do the draws with @MCVARDODRAWS. Then the @MCGRAPHIRF procedure can be used to do more specific graphs. (It sounds like you want the ONLYSHOCKS option on that).
Ozmando
Posts: 52
Joined: Sun Jul 15, 2012 4:04 pm

TomDoan wrote: Mon Feb 19, 2024 8:54 am Do the draws with @MCVARDODRAWS. Then the @MCGRAPHIRF procedure can be used to do more specific graphs. (It sounds like you want the ONLYSHOCKS option on that).
Thanks Tom for the very useful help.
I have managed to modify the code.
I am now left with two main issues, please.

1) header and footer not printed
2)how to change the graphs color

This is the modified code:

Code: Select all

``````system(model=varmodel)
variables inf govcons  debt gdp rir
lags 1 to lags 2
det  constant  tot{0 2}

end(system)
dec vect[strings] vlabels

compute implabel = || \$
"Inflation",\$
"Govcons",\$
"debt",\$
"gdp",\$
"rir"||

estimate
*
@mcvardodraws(model=varmodel,draws=mcdraws,steps=nsteps)
@mcgraphirf(model=varmodel,varlabels=vlabels,ONLYSHOCKS=||3||, header='Response to debt shocks', PAGE=ONE,\$
center=median,percent=||.10,.90||,\$
footer="year after shock")``````
Thanks
Ozey
TomDoan
Posts: 7536
Joined: Wed Nov 01, 2006 4:36 pm

I'm not sure what your plan is with the PAGE=ONE option, but a separate page for each variable means that it makes little sense to have a universal header (which is why you don't see one)---the header would be the same on each page.

What's wrong with the colors? They're the usual black with blue (which will turn to dots in black and white) for the bounds.
Ozmando
Posts: 52
Joined: Sun Jul 15, 2012 4:04 pm

TomDoan wrote: Mon Feb 19, 2024 3:21 pm I'm not sure what your plan is with the PAGE=ONE option, but a separate page for each variable means that it makes little sense to have a universal header (which is why you don't see one)---the header would be the same on each page.

What's wrong with the colors? They're the usual black with blue (which will turn to dots in black and white) for the bounds.
Thanks Tom.
I see your point on the heading. Will fix that. I guess it is the same for the footer.
In relation to the color, my question was whether this can be changed or is it the default?
Regards,
ozey
TomDoan
Posts: 7536
Joined: Wed Nov 01, 2006 4:36 pm

You'd have to be more explicit about what you are hoping to get.

@MCGRAPHIRF uses styles 1 (by default solid black, for the response) and 2 (by default solid blue, or dots in black and white) for the bounds. You can re-define those if you want.
Ozmando
Posts: 52
Joined: Sun Jul 15, 2012 4:04 pm

TomDoan wrote: Wed Feb 21, 2024 11:06 am You'd have to be more explicit about what you are hoping to get.

@MCGRAPHIRF uses styles 1 (by default solid black, for the response) and 2 (by default solid blue, or dots in black and white) for the bounds. You can re-define those if you want.
Thanks Tom.
In the previous code that I used the graphs were based on the following colours for the response and the confidence bands:

Code: Select all

``````# resp(j)   /8
# upper(j) / 6
# lower(j) / 6``````
I wanted to keep the same colours, if possible please with @MCGRAPHIRF.
Regards,
ozey
TomDoan
Posts: 7536
Joined: Wed Nov 01, 2006 4:36 pm

See

https://estima.com/ratshelp/stylesheets.html

Use GRPARM instructions to redefine styles LINE_COLOR_01 and LINE_COLOR_02 as what are the standard 8 and 6 colors.