*
* IMPULSES.RPF
* Example of computing and graphing impulse responses (with Cholesky
* factor shocks).
*
* RATS User's Guide, Example from Section 7.6.
*
open data oecdsample.rat
calendar(q) 1981
data(format=rats) 1981:1 2006:4 can3mthpcp canexpgdpchs canexpgdpds $
canm1s canusxsr usaexpgdpch
*
* Scaling the log series by 100 gives the responses a more natural scale.
*
set logcangdp = 100.0*log(canexpgdpchs)
set logcandefl = 100.0*log(canexpgdpds)
set logcanm1 = 100.0*log(canm1s)
set logusagdp = 100.0*log(usaexpgdpch)
set logexrate = 100.0*log(canusxsr)
*
*************************************************************************
*
* The only lines that need to be changed are the ones tagged with ;*<<<<<<
*
compute nlags = 5 ;*<<<<<<
compute nsteps = 24 ;*<<<<<<
*
system(model=canmodel)
variables logusagdp logexrate can3mthpcp logcanm1 logcangdp logcandefl ;*<<<<<<<<
lags 1 to nlags
det constant
end(system)
*
* To help create publication-quality graphs, this sets longer labels for
* the series. These are used both in graph headers and key labels.
*
compute [vect[strings]] implabel=|| $ ;* <<<<<<
"US Real GDP",$
"Exchange Rate",$
"Short Rate",$
"M1",$
"Canada Real GDP",$
"CPI"||
estimate(noprint)
compute neqn=%nvar
*
* The procedure VARIRF does the graphs shown below without the extra
* programming. You can choose the graph pages to be organized by shocks
* or by variables.
*
@VARIRF(model=canmodel,steps=nsteps,$
varlabels=implabel,page=byshocks)
@VARIRF(model=canmodel,steps=nsteps,$
varlabels=implabel,page=byvariables)
*
* @montevar is a simple procedure for doing a standard set of graphs
* with error bands. If you need different formatting on the graphs, use
* a combination of @MCVARDoDraws and @MCGraphIRF (or even more flexibly,
* @MCProcessIRF combined with custom graphs).
*
@montevar(draws=4000,model=canmodel,$
shocks=implabel,varlabels=implabel,footer="Responses with MC error bands")
*
declare rect[series] impblk(neqn,neqn)
declare vect[series] scaled(neqn)
*
* This computes the full set of impulse responses, which are in the
* series in IMPBLK. IMPBLK(i,j) is the response of variable i to a shock
* in j.
*
impulse(model=canmodel,result=impblk,noprint,$
steps=nsteps,cv=%sigma)
*
* This loop plots the responses of all series to a single series. The
* response of a series is normalized by dividing by its innovation
* variance. This allows all the responses to a shock to be plotted on a
* single scale. Note that these graphs get a bit hard to read with more
* than five or six variables.
*
do i=1,neqn
compute header="Plot of responses to "+implabel(i)
do j=1,neqn
set scaled(j) = (impblk(j,i))/sqrt(%sigma(j,j))
end do j
graph(header=header,key=below,klabels=implabel,$
number=0,series=scaled) neqn
end do i
*
* And this loop graphs the responses of a variable to all shocks. These
* don't have to be normalized.
*
do i=1,neqn
compute header="Plot of responses of "+implabel(i)
graph(header=header,key=below,klabels=implabel,number=0,$
series=%scol(impblk,i)) neqn
end do i
*
* This is specific to this model, as it is set up.
* Normalize interest rate shock to -1.0 impact on itself.
*
compute factor=%decomp(%sigma)
compute [vector] rshock=%xcol(factor,3)
compute rshock=-1.0*rshock/rshock(3)
impulse(model=canmodel,shock=rshock,steps=nsteps,$
results=to_r,noprint)
graph(number=0,header=$
"Response of Canadian RGDP to expansionary rate shock") 1
# to_r(5,1)