Code: Select all
open data lgdp.txt
calendar(q) 1947
data(format=free,org=columns) 1947:01 1998:02 lgdp
*
* Everything is run on 100*log data
*
set lgdp = 100.0*lgdp
*
@NBERCycles(down=recession)
*
* UC-0 decomposition with AR(2) cycle, fixed trend rate.
*
nonlin mu sn ph1 ph2 se
*
dec frml[rect] af
dec frml[vect] zf
dec frml[symm] swf
*
frml af = ||1.0,0.0,0.0|$
0.0,ph1,ph2|$
0.0,1.0,0.0||
frml zf = ||mu,0.0,0.0||
frml swf = %diag(||sn^2,se^2||)
*
compute [vect] c=||1.0,1.0,0.0||
compute [rect] f=%identity(2)~~%zeros(1,2)
*
* Get initial guess values
*
filter(type=hp) lgdp / gdp_hp
set gap_hp = lgdp - gdp_hp
linreg gap_hp
# gap_hp{1 2}
compute ph1=%beta(1),ph2=%beta(2),se=sqrt(%seesq)
set trend = t
linreg gdp_hp
# constant trend
compute mu=%beta(2)
compute sn=sqrt(.1*%seesq)
*
* In order to be comparable with the BN decomposition (which is a
* "filtered" calculation), this uses filtered rather than smoothed
* estimates of the components.
*
dlm(presample=ergodic,a=af,z=zf,sw=swf,c=c,f=f,y=lgdp,method=bfgs,type=filter) / states0
*
set cycle0 = states0(t)(2)
set trend0 = states0(t)(1)
*
graph(footer="Figure 1 UC-0 Cycle, US Real GDP. Percent Deviation from Trend",$
shaded=recession)
# cycle0