how to estimate monthly output gap?
Posted: Sun Dec 08, 2019 8:48 am
Dear Tom:
I have an idea that using unobserved component filter to estimate the monthly output gap based on quarterly real log GDP data. I know that this is a difficult task, even impossible task, or trivial one. When I retrieve academic paper, it seems no one try to do it.
I present my idea in detail. I had two way to get my aim: Two stage and one stage method. Firstly, I use @disaggredate procedure to distribute quarterly real GDP to monthly GDP, then I use UC model to decompose it into trend and cycle or gap. However I get wrong outcome. Meantime I use HP filter to get HP cycle based on monthly and quarterly frequency respectively, these outcomes seem reasonable. Monthly HP cycle has same pattern with quarterly HP cycle, but more refined. As for UC cycle, the monthly one has different pattern with quarterly one, is more like white noise.
I use same HP filter option, though the variance ratio,lamba is different in 1600 for quarterly and 14400 for monthly.
For UC model, I use same configuration, eg, local trend model for quarterly and monthly model.
In UC model, HP filter is used to get initial guess value, but these outcomes is not accurate but reasonable. however, the outcome of monthly UC model can not be accepted. Why and how to improve it.
monthlu code
quarterly code:
Please Tom help me.
I have an idea that using unobserved component filter to estimate the monthly output gap based on quarterly real log GDP data. I know that this is a difficult task, even impossible task, or trivial one. When I retrieve academic paper, it seems no one try to do it.
I present my idea in detail. I had two way to get my aim: Two stage and one stage method. Firstly, I use @disaggredate procedure to distribute quarterly real GDP to monthly GDP, then I use UC model to decompose it into trend and cycle or gap. However I get wrong outcome. Meantime I use HP filter to get HP cycle based on monthly and quarterly frequency respectively, these outcomes seem reasonable. Monthly HP cycle has same pattern with quarterly HP cycle, but more refined. As for UC cycle, the monthly one has different pattern with quarterly one, is more like white noise.
I use same HP filter option, though the variance ratio,lamba is different in 1600 for quarterly and 14400 for monthly.
For UC model, I use same configuration, eg, local trend model for quarterly and monthly model.
In UC model, HP filter is used to get initial guess value, but these outcomes is not accurate but reasonable. however, the outcome of monthly UC model can not be accepted. Why and how to improve it.
monthlu code
Code: Select all
open data US_rmGDP.xls
calendar(m) 1947:01
data(format=xls,org=col) 1947:01 2019:10 rmgdp3
set lgdp = log(rmgdp3) * 100
* Do a standard HP filter
*
filter(type=hp) lgdp / hptrend
graph(footer="Log GDP with HP Estimated Trend",klabels=||"GDP","HP Trend"||,key=upleft) 2
# lgdp
# hptrend
set hpcycle = lgdp - hptrend
graph(footer="Cycle Estimate from HP Filter")
# hpcycle
graph(footer="Cycle Estimate from HP Filter 2000:01-2002:12")
# hpcycle 2000:01 2002:12
****************************************************
*
* UC with AR(2) process for cycle
*
* Standard local trend model
*
dec rect at(2,2) ft(2,2)
compute at=||1.0,1.0|0.0,1.0||
compute ft=%identity(2)
*
* Standard AR(2) model
*
dec real phi1 phi2
dec rect ar2(2,2) far2(2,1)
compute ar2=||phi1,phi2|1.0,0.0||
compute far2=||1.0|0.0||
*
* Function to patch the current g's into the overall transition matrix
*
function afunc t
type rect afunc
type integer t
*
compute %psubmat(ar2,1,1,||phi1,phi2||)
compute afunc=at~\ar2
end
*
* Combined "F" and "C" matrices
*
compute f=ft~\far2
compute c=||1.0,0.0,1.0,0.0||
*
dec rect g(2,4)
input g
0 0 1 0
0 0 0 1
linreg hpcycle
# hpcycle{1 2}
compute phi1=%beta(1),phi2=%beta(2),se=sqrt(%seesq)
compute sigmac=.01*se, sigmaz=0.01*se, sigmat=.050*se
nonlin phi1 phi2 sigmac sigmaz sigmat
*
* Do Kalman smooth for estimate of the trend
*
dlm(a=afunc(t),c=c,f=f,sw=%diag(||sigmaz,sigmat,sigmac||),$
type=smooth,presample=ergodic,y=lgdp,method=bfgs,iters=100,$
pmethod=simplex,piter=10,reject=(abs(phi1+phi2)>=1.0)) / xstatesf
set fixtrend = xstatesf(t)(1)
graph(footer="Log GDP with UC",$
klabels=||"GDP","UC-AR(2) Trend"||,key=upleft) 2
# lgdp
# fixtrend
set SM_cycle = xstatesf(t)(3)
graph(footer="Smooth: Cycle Estimate with UC")
# SM_cycle
*
*
dlm(a=afunc(t),c=c,f=f,sw=%diag(||sigmaz,sigmat,sigmac||),$
type=filter,presample=ergodic,y=lgdp) / xstatesx
set fixtrend = xstatesf(t)(1)
graph(footer="Log GDP with UC Cycle",$
klabels=||"GDP","UC Trend"||,key=upleft) 2
# lgdp
# fixtrend
set Fl_cycle = xstatesf(t)(3)
graph(footer="Filter: Cycle Estimate with UC")
# Fl_cycle
graph(footer="Cycle Estimate with UC ") 2
# SM_cycle
# Fl_cycle
graph(footer="Filter: Cycle Estimate with UC 2000:01-2002:12")
# Fl_cycle 2000:01 2002:12Code: Select all
open data us_gdp.xls
calendar(q) 1947:1
data(format=xls,org=columns) 1947:01 2019:03 gdp
*
* Everything is run on 100*log data
set lgdp = 100.0 * log(gdp)
*
@NBERCycles(down=recession)
*@LSUNIT(MODEL=BREAK,BREAKS=3) LGDP
*@ZIVOT(BREAK=TREND) LGDP
* @LPUNIT(BREAK=BOTH,METHOD=AIC) LGDP
*
* Do a standard HP filter
*
filter(type=hp) lgdp / hptrend
graph(footer="Log GDP with HP Estimated Trend",klabels=||"GDP","HP Trend"||,key=upleft) 2
# lgdp
# hptrend
set hpcycle = lgdp - hptrend
graph(footer="Cycle Estimate from HP Filter")
# hpcycle
graph(footer="Cycle Estimate from HP Filter")
# hpcycle 2000:01 2002:04
linreg hpcycle
# hpcycle{1 2}
compute phi1=%beta(1),phi2=%beta(2),se=sqrt(%seesq)
****************************************************
*
* UC with AR(2) process for cycle
*
* Standard local trend model
*
dec rect at(2,2) ft(2,2)
compute at=||1.0,1.0|0.0,1.0||
compute ft=%identity(2)
*
* Standard AR(2) model
*
dec real phi1 phi2
dec rect ar2(2,2) far2(2,1)
compute ar2=||phi1,phi2|1.0,0.0||
compute far2=||1.0|0.0||
*
* Function to patch the current g's into the overall transition matrix
*
function afunc t
type rect afunc
type integer t
*
compute %psubmat(ar2,1,1,||phi1,phi2||)
compute afunc=at~\ar2
end
*
* Combined "F" and "C" matrices
*
compute f=ft~\far2
compute c=||1.0,0.0,1.0,0.0||
*
* "G" matrix for handling state space model with combined unit roots
* (for the local trend states) and stationary states (for the cycle).
*
dec rect g(2,4)
input g
0 0 1 0
0 0 0 1
*
nonlin phi1 phi2 sigmac sigmaz sigmat
compute sigmaz=.0001,sigmat=.0001,sigmac=.001
*
* Do Kalman smooth for estimate of the trend
*
dlm(a=afunc(t),c=c,f=f,sw=%diag(||sigmaz,sigmat,sigmac||),$
type=smooth,presample=ergodic,y=lgdp,method=bfgs,iters=100,$
pmethod=simplex,piter=10,reject=(abs(phi1+phi2)>=1.0)) / xstatesf
set fixtrend = xstatesf(t)(1)
graph(footer="Log GDP with UC-AR(2) Cycle",$
klabels=||"GDP","UC-AR(2) Trend"||,key=upleft) 2
# lgdp
# fixtrend
set SM_cycle = xstatesf(t)(3)
graph(footer="Smooth: Cycle Estimate with UC-AR(2)",shaded=recession)
# SM_cycle
*
*
dlm(a=afunc(t),c=c,f=f,sw=%diag(||sigmaz,sigmat,sigmac||),$
type=filter,presample=ergodic,y=lgdp) / xstatesx
set fixtrend = xstatesf(t)(1)
graph(footer="Log GDP with UC-AR(2) Cycle",$
klabels=||"GDP","Fixed AR(2) Trend"||,key=upleft) 2
# lgdp
# fixtrend
set Fl_cycle = xstatesf(t)(3)
graph(footer="Filter: Cycle Estimate with UC-AR(2)",shaded=recession)
# Fl_cycle
graph(footer="Cycle Estimate with AR(2) ",shaded=recession) 2
# SM_cycle
# Fl_cycle
graph(footer="Filter: Cycle Estimate with UC-AR(2)")
# Fl_cycle 2000:01 2002:04