Dear Prof. Diaz-Emparanza

I greatly appreciate your taking the time to reply.  I looked at the example in the user’s guide, and I see the similarities.  A few things still confuse me, however.

Given my system and data, I have r = 2, n =1, and T = 93. My kalman matrices should therefore have the following dimensions:

y (obsy, T x n) 93 x 1 
H (obsymat, r x n) 2 x 1 : H = {1 ; 1} 
R (obsvar, n x n) 1 x 1 : R = {s2} 
F (statemat, r x r) 2 x 2 : F = {1, 0; 0, rho} 
Q (statevar, r x r) 2 x 2 : Q = {s1, 0; 0, 0}

Do you agree?

So, using the Gretl code included in the user’s guide as a template, my system would be written:

function matrix local_level (series y)

    scalar s1 = 1 
    scalar s2 = 1 
    scalar rho = 1

    matrix H = {1 ; 1} 
    matrix F = {1, 0; 0, rho} 
    matrix Q = {s2, 0; 0, s1}

kalman 
    obsy y 
    obsymat H 
    statemat F 
    statevar Q 
    obsvar s1 
end kalman --diffuse

mle ll = ERR ? NA : $kalman_llt 
    F[1,1] = s2 
    Q[2,2]= rho 
    ERR = kfilter() 
    params s1 s2 rho 
end mle 
return s1 ~  s2 ~ rho 
end function

function series loclev_sm (series y, scalar s1, scalar s2, scalar rho) 
kalman 
    obsy y 
    obsymat H 
    statemat F 
    statevar Q 
    obsvar s1 
end kalman --diffuse 
series ret = ksmooth() 
return ret 
end function

matrix Vars = local_level(y) 
muhat = loclev_sm(y, Vars[1], Vars[2], Vars[3])

This seems to work up to where the code invokes muhat, then I get “Data error”:

gretl version 1.8.4 
Current session: 2009-09-17 12:19 
? function matrix local_level (series y) 
> > scalar s1 = 1 
> scalar s2 = 1 
> scalar rho = 1 
> > matrix H = {1 ; 1} 
> matrix F = {1, 0; 0, rho} 
> matrix Q = {s2, 0; 0, s1} 
> > kalman 
> obsy y 
> obsymat H 
> statemat F 
> statevar Q 
> obsvar s1 
> end kalman --diffuse 
> > mle ll = ERR ? NA : $kalman_llt 
> F[1,1] = s2 
> Q[2,2]= rho 
> ERR = kfilter() 
> params s1 s2 rho 
> end mle 
> return s1 ~  s2 ~ rho 
> end function 
? function series loclev_sm (series y, scalar s1, scalar s2, scalar rho) 
> kalman 
> obsy y 
> obsymat H 
> statemat F 
> statevar Q 
> obsvar s1 
> end kalman --diffuse 
> series ret = ksmooth() 
> return ret 
> end function 
? matrix Vars = local_level(y) 
Using numerical derivatives 
Tolerance = 1.81899e-012 
Function evaluations: 46 
Evaluations of gradient: 16

Model 19: ML, using observations 2001:10-2009:06 (T = 93) 
ll = ERR ? NA : $kalman_llt 
Standard errors based on Outer Products matrix

             estimate    std. error   t-ratio   p-value 
  ------------------------------------------------------ 
  s1         -1.66438    0.993641    -1.675    0.0939   * 
  s2          0.238300    0.582520     0.4091   0.6825  
  rho         8.71710     1.77558      4.909    9.13e-07 ***

Log-likelihood      -234.0736   Akaike criterion     474.1471 
Schwarz criterion    481.7449   Hannan-Quinn         477.2149

Replaced matrix Vars 
? muhat = loclev_sm(y, Vars[1], Vars[2], Vars[3]) 
Data error

Error executing script: halting 
> muhat = loclev_sm(y, Vars[1], Vars[2], Vars[3])

Again, I appreciate your help and look forward to your feedback.