Kalman Filter

Discussion of State Space and Dynamic Stochastic General Equilibrium Models
Tony
Posts: 4
Joined: Sun Oct 31, 2010 8:09 pm

Kalman Filter

Unread post by Tony »

Dear Friends,
I have some questions need your help.
For example, we need to estimate a model
Y(t)= B(t)*X(t)+v
and assume B(t) follow simple transitional process
B(t)=aB(t-1)+u and assume the parameter A to be 1.

As to my understanding, we should use the following code:

Code: Select all

compute sv=0.1**2,seta=0.02**2,seps=0.04**2
dlm(y=y,c=||1.0,x||,sv=sv,sw=%diag(||seta,seps||),exact,type=smoothed) / xstates vstates
*
linreg y
# constant x
*
set tv1 = xstates(t)(2)
graph(vgrid=%beta(2),footer="Smoothed estimates of time-varying coefficient")
# tv1
Question: Am I doing the correct staff?

The RATS book says that the function RLS do recursive estimation using kalman filter , then I run as follows,

Code: Select all

rls(cohistory=coefs) y
# constant x
graph(vgrid=%beta(2),footer="time-varying coefficien")
# coefs(2)
but the results are different. May I know why?

As curiosity, I also estimated rolling coefficients as follows:

Code: Select all

set beta 1 98 =0
do i=3, 98
linreg(noprint) y 2 i
# constant x
com beta(i)=%beta(2)
end do
graph(vgrid=%beta(2),footer="time-varying coefficient")
# beta 3 *
The results from this estimation is exactly same as from RLS which is based on Kalman filter. I am wondering so what is the purpose to have RLS if it does not improve anything better than simple rolling estimate.

Then I did the following:

Code: Select all

Equation kalcoef y
# constant x
system kalcoef
end(system)
estimate(cohistory=cokalman) 1 10
do entry=11, 98
kalman(cohistory=cokalman) 3
end do entry
graph(vgrid=%beta(2),footer="time-varying coefficient")
# cokalman(2) 3 *
Is there anyone can help to clarify the difference of all these? Your kind help on these matters are highly appreciated.
[/size]
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Kalman Filter

Unread post by TomDoan »

From the User's Guide (section 5.7 in Version 7, 2.6 in Version 8)
The instruction RLS does Recursive Least Squares. This is the equivalent of a sequence
of least squares regressions, but done in a very efficient way.
From later on the same page:
Note that RLS is designed for recursive estimation only. If you need to do something
more than that (for instance, you want to generate forecasts at each stage), you can
use the instruction KALMAN, which does the same type of sequential estimation, but
only updates one entry for each instruction. If you want to allow the (true) coefficients
in (27) to be time-varying, you need to set up a state-space model (Chapter 10) [references are for Version 8 manual].
So RLS, KALMAN and the sequence of LINREG's produce the same coefficient estimates, but apply in different situations depending upon what you want to do with the sequence of regressions. All of these are for the situation where the "u" in your model is zero. That's a fixed coefficient model, where the only difference in the coefficient estimates is due to the data used.

If "u" is non-zero, then you have a time-varying coefficients (or TVP) model which cannot be estimated with RLS or LINREG. Generally, those will be best analyzed with DLM using something similar to what you indicated at the start. However, the precise set up will depend upon your model, and copying variance settings from a different set of data isn't likely to give good results. (And, in particular, not from that Tsay example, which has variances that are completely wrong for the data set). You might want to take a look at the forum discussion:

http://www.estima.com/forum/viewtopic.php?f=5&t=381
Post Reply