Page 1 of 1

Output gap calculation

Posted: Fri Apr 25, 2008 12:22 pm
by TomDoan
This calculates an estimate of the output gap using a VAR.

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

Quah-Vahey(1995)

Posted: Thu May 15, 2008 2:36 pm
by nazif
dear
i'm trying to replicate the work of Quah and Vahey (1995) mainly based on blanchard quah decomposition to obtain underlying trend of inflation which is called also as core inflation in the literature. is it possible use this output gap code for this purpose?
Thanks.

Quah-Vahey(1995)

Posted: Fri May 16, 2008 3:18 pm
by TomDoan
nazif wrote:dear
i'm trying to replicate the work of Quah and Vahey (1995) mainly based on blanchard quah decomposition to obtain underlying trend of inflation which is called also as core inflation in the literature. is it possible use this output gap code for this purpose?
Thanks.
Yes. That's also done using the historical decomposition. For their case, you want to take the demand shock, not the supply shock. Also, because the VAR is estimated in first differences (of log output and the inflation rate), it's necessary to integrate up the decomposition, which can be done most easily with SET. The full example is at:

http://www.estima.com/forum/viewtopic.php?f=8&t=1156

Code: Select all

*
* Estimate a 12 lag VAR on the growth rate of output and the change in the
* inflation rate.
*
system(model=qvdmodel)
variables ygr1 chinf1
lags 1 to 12
det constant seasons{-10 to 0} trend apr1990
end(system)
estimate(noprint)
*
* Compute the BQ factorization. The first shock will be the supply shock (the one
* with a non-zero long-run response for output), the second will be the core
* inflation shock.
*
compute bqfactor=%bqfactor(%sigma,%varlagsums)
*
* Compute the historical decomposition of the first differenced data. The effect
* of the core inflation shocks will be in the 3rd row of the qvdhistory
* RECT[SERIES]. (That has the cumulated responses to the 2nd shock).
*
history(factor=bqfactor,model=qvdmodel,results=qvdhistory,add)
*
* What we have now are decompositions of the growth rate of output and the change
* in the inflation rate. We need to integrate those up. We first copy out the
* actual data needed for pre-sample values.
*
set coreinfl = inf1
set coreip   = indprod
*
set coreinfl %regstart() %regend() = coreinfl{1}+qvdhistory(3,2)
set coreip   %regstart() %regend() = coreip{1}+qvdhistory(3,1)
*
* The core inflation rate shown in the article is the 12th difference of the
* historical decomposition of the price index (in 100 x log() form). We have to
* integrate up one more time to get the price index.
*
set corepidx = lrpi
set corepidx %regstart() %regend() = corepidx{1}+coreinfl
set coreinfl %regstart() %regend() = corepidx-corepidx{12}
*
print %regstart() %regend() coreip coreinfl
graph(footer="Output") 2
# indprod
# coreip

Quah-Vahey 1995

Posted: Sat May 17, 2008 6:09 am
by nazif
Dear Doan,
Thanks for your prompt reply and help again. In that paper they used bivariate VAR model consisting of output and inflation, core inflation defined as permanent component of inflation that has no long run effect on output.
Thanks for your help again.