'cubic spline smooothing using sspace
'for version 4
'last checked 10/27/2000 h

'change path to program path
%path = @runpath
cd "{%path}"

' load workfile
load nber
series y = m03054

smpl @first 42:06

'set smoothing parameter (signal-to-noise ratio)
!q = 0.005

'setup sspace
sspace ss1
ss1.append @signal y = sv1 + [var=1.0]
ss1.append @state sv1 = sv1(-1) + sv2(-1) + [ename=u1]
ss1.append @state sv2 = sv2(-1) + [ename=u2]
'c(1)*c(1) is the smoothing parameter (signal-to-noise ratio)
'ss1.append @evar cov(u1,u1)=c(1)*c(1)/3
'ss1.append @evar cov(u1,u2)=0.5*c(1)*c(1)
'ss1.append @evar cov(u2,u2)=c(1)*c(1)
ss1.append @evar cov(u1,u1)=!q/3
ss1.append @evar cov(u1,u2)=0.5*!q
ss1.append @evar cov(u2,u2)=!q
	
'parse (no parameters to estimate)
ss1.ml(d,m=100,c=1e-9)

'get smoothed estimate
ss1.makesignals(t=smooth) ys1

'get HP filtered series
!lambda = 14400
y.hpf(!lambda) ys2

'plot
graph graph1.line y ys1 ys2
graph1.setelem(1) legend(Actual)
graph1.setelem(2) legend(Cubic spline smoothing (q = !q))
graph1.setelem(3) legend(Hodrick-Prescott filter (lambda = !lambda))
graph1.legend position(.5,0) -inbox
graph1.options size(6,2)
show graph1