Personally, I'd liked
 * implement this as a variant of our native hpfilt() function,
because it will work very quickly
But > * Put the code below in the Kalman filter chapter 
will be good as a example
Kalman filter is very valuable and powerful thing
But as for me the docs are somewhat difficult:
Every additional example will be helpful
Oleh
8 березня 2018, 17:20:23, від "Riccardo (Jack) Lucchetti"
<r.lucchetti(a)univpm.it>:
 
 Folks,
 
 I just implemented the one-sided HP filter as per Stock & Watson (1999), 
 "Forecasting Inflation", JME. It was quite easy, in fact. The Hansl code 
 is below.
 
 However, I'd like to ask the community a question: how should we use this: 
 I have three possibilities:
 
 * Put the code below in the Kalman filter chapter of the User's Guide, as 
 an example of how you do simple things of some practival value;
 
 * implement this as a function package (but then, we already have the 
 Christiano-Fitzgerald filter, and it may make sense to coalesce the two 
 filters into one package)
 
 * implement this as a variant of our native hpfilt() function, with an 
 extra boolean flag for one-sidedness.
 
 Opinions?
 
 <hansl>
 function series oshpfilt(series y, scalar lambda[0])
 
      if lambda == 0
          lambda = 100 * $pd^2
      endif
 
      # State transition matrix
      matrix F = {2,-1;1,0}
      # Observation matrix
      matrix H = {1;0}
      # Covariance matrix in the state equation
      matrix Q = diagcat(1/lambda, 0)
 
      ssm = ksetup(y, H, F, Q)
      ssm.obsvar = 1
      ssm.inistate = {2*y[1]-y[2] ; 3*y[1]-2*y[2]}
 
      err = kfilter(&ssm)
 
      series ret = err ? NA : y - ssm.state[,2]
      return ret
 end function
 
 # --- example ----------------------------------------------
 
 clear
 open fedstl.bin
 data houst
 series y = log(houst)
 
 series hp1 = oshpfilt(y) # one-sided
 series hp2 = hpfilt(y)   # two-sided (traditional)
 
 series t1 = y - hp1
 series t2 = y - hp2
 </hansl>
 
 
 
 
 -------------------------------------------------------
    Riccardo (Jack) Lucchetti
    Dipartimento di Scienze Economiche e Sociali (DiSES)
 
    Università Politecnica delle Marche
    (formerly known as Università di Ancona)
 
    > r.lucchetti@univpm.ithttp://www2.econ.univpm.it/servizi/hpp/lucchetti
 -------------------------------------------------------
 _______________________________________________
 Gretl-users mailing list
 Gretl-users@lists.wfu.eduhttp://lists.wfu.edu/mailman/listinfo/gretl-users