Cublic Spline

Econometrics questions and discussions
e1983
Posts: 20
Joined: Sun Aug 28, 2011 2:32 am

Cublic Spline

Unread post by e1983 »

Does anyone know if it is possible to use cubic spline data interpolation in RATS?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Cublic Spline

Unread post by TomDoan »

e1983 wrote:Does anyone know if it is possible to use cubic spline data interpolation in RATS?
The Durbin and Koopman examples DURKP136.RPF and DURKP172.RPF do cubic splines. Both of those have "knots" at every observation. For fewer knots, you can use the general idea below. For a specific example of this applied to bond yields, see http://www.estima.com/forum/viewtopic.php?f=8&t=2150.

Code: Select all

compute nk = 3           ;* number of spline knots

*** Compute Break Points
declare vector[integer] nks(nk+1)
 compute nks(1) = 1
 do i = 1, nk
  compute frac = (float(i))/(float(nk+1))
  compute nks(i+1) = fix(frac*(float(nlast-nfirst+1)))
 end do i
declare vector[series] splreg(nk+4)
set splreg(1) = 1.
set splreg(2) = (t-nfirst+1)
set splreg(3) = (t-nfirst+1)*(t-nfirst+1)

do ik = 1,nk+1
 set t1 = splreg(2)(t) - nks(ik)
 set splreg(ik+3) = 0.5*t1(t)*t1(t)*t1(t)
 set splreg(ik+3) = splreg(ik+3)*(splreg(2)(t)>nks(ik))
end do ik

*** Detrend series using cubic splines: USER CHOOSES HERE
linreg(noprint) y / yr
# splreg(1) to splreg(nk+4)
linreg(noprint) rl_rs / rlrs
# splreg(1) to splreg(nk+4)
set y = yr
set rl = rlrs + rs
Post Reply