Code: Select all
*
* The following (based upon the RATS example CVMODEL.PRG) demonstrates how to
* compute the output gap using a VAR. It shows two equivalent ways to do this,
* one using HISTORY, the other FORECAST with PATHS. This requires that you have
* some form of structural model, whether done with CVMODEL, the SHORTANDLONG
* procedure, %BQFACTOR or something else, with the structural shocks that can be
* separated into supply and non-supply shocks.
*
* As written, this requires version 7 of RATS. It can be modified for earlier
* versions by changing the CALENDAR to cal 1981 1 4 and replacing the "FROM" and
* "TO" options on HISTORY and FORECAST with hend-hstart+1 and hstart for the
* "periods" and "start" parameters.
*
open data oecdsample.rat
calendar(q) 1981
data(format=rats) 1981:1 2006:4 can3mthpcp canexpgdpchs canexpgdpds canm1s canusxsr usaexpgdpch
*
set logcangdp = log(canexpgdpchs)
set logcandefl = log(canexpgdpds)
set logcanm1 = log(canm1s)
set logusagdp = log(usaexpgdpch)
set logexrate = log(canusxsr)
*
system(model=canmodel)
variables logusagdp logcangdp can3mthpcp logexrate logcandefl logcanm1
lags 1 to 4
det constant
end(system)
*
estimate(noprint,resids=varresids)
compute hstart=%regstart(),hend=%regend()
*
dec frml[rect] afrml bfrml
nonlin uf1 cr1 cf1 rf2 mf1 mm2
frml bfrml = ||1.0,0.0,uf1,0.0,0.0,0.0|$
cr1,1.0,cf1,0.0,0.0,0.0|$
0.0,0.0,1.0,rf2,0.0,0.0|$
0.0,0.0,0.0,1.0,0.0,0.0|$
mf1,0.0,0.0,0.0,1.0,mm2|$
0.0,0.0,0.0,0.0,0.0,1.0||
compute uf1=cr1=cf1=rf2=mf1=mm2=pm2=0.0
*
* This is estimated by using the genetic method first, then polishing the
* estimates with bfgs. In practice, you might want to repeat this several times
* to test whether there are global identification problems.
*
cvmodel(b=bfrml,method=bfgs,pmethod=genetic,piters=50,factor=bfactor) %sigma
*
* Because the shocks don't really correspond one-to-one with the variables, the
* labels option is used on ERRORS to give them the desired labels.
*
errors(model=canmodel,factor=bfactor,steps=28,window="BModel",$
labels=||"Real 1","Real 2","Fin 1","Fin 2","Nom 1","Nom 2"||)
*
* Method 1 - Using HISTORY
* The series of interest is Canadian GDP, which is the second series in the
* model. "Potential" GDP is the base forecast plus the effects of the supply
* shocks (which, in this case, we'll assume are the two real shocks). As the
* structural model is set up, the two real shocks are the first two structural
* shocks. The decomposition of the second series is in the second row of the
* RECT[SERIES] called history. To get potential GDP, we need to add history(1,2)
* (the base forecast) with history(2,2) and history(3,2) (the cumulated effects of
* the 1st and 2nd shocks). As an alternative, we could get the gap directly by
* adding the series history(4,2), history(5,2), history(6,2) and history(7,2),
* which will be the cumulated effects of the four non-supply shocks.
*
history(results=history,model=canmodel,factor=bfactor,from=hstart,to=hend)
set potgdp = history(1,2)+history(2,2)+history(3,2)
graph 2
# potgdp
# logcangdp
set gap = potgdp-logcangdp
graph
# gap
*
* Method 2 - Using FORECAST with PATHS
* What we need here is to get the residuals stripped of the effects of the
* non-supply shocks. If u are the VAR residuals and v are the structural
* residuals, u(t)=Fv(t), or v(t)=inv(F)u(t). To shut out the non-supply shocks,
* we pre-multiply v by a diagonal matrix with 1's at the positions corresponding
* to the supply shocks and zeros elsewhere. Pre-multiplying that by F itself will
* transform back to the standard residual space. Putting that together, we want F
* x D x inv(F) times the VAR residuals. The following produces the transformed
* residuals - supplymask is a vector with 1's in the slots for the supply shocks
* and 0's elsewhere.
*
compute supplymask=||1.0,1.0,0.0,0.0,0.0,0.0||
compute supplyonly=bfactor*%diag(supplymask)*inv(bfactor)
dec vect[series] supplyshocks(6)
do i=1,6
set supplyshocks(i) hstart hend = %dot(%xrow(supplyonly,i),%xt(varresids,t))
end do i
*
* FORECAST with PATHS will now give the variables forecast with the addition of
* the supply shocks. withshocks(2) will be potential Canadian GDP.
*
forecast(paths,from=hstart,to=hend,model=canmodel,results=withshocks)
# supplyshocks
set potgdp = withshocks(2)
set gap = potgdp-logcangdp