Running Kalman filter with initial data

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 5:52 am

Hi everyone,

I'm sorry to post again a topic on Kalman Filter estimation but I'm really stuck...

I'm trying to estimate time varying betas with a kalman filter. I used to work with matlab but I have to use Eviews now and I'm new here...

Here is my workfile and the code :

@signal CON_AR = sv1*BONDS + sv2*CMDTY + sv3*CREDITS + sv4*EMMB + sv5*EMME + sv6*SP + sv7*USD + [var = exp(c(1))]

@state sv1 = sv1(-1) + [var = exp(c(2))]
@state sv2 = sv2(-1) + [var = exp(c(3))]
@state sv3 = sv3(-1) + [var = exp(c(4))]
@state sv4 = sv4(-1) + [var = exp(c(5))]
@state sv5 = sv5(-1) + [var = exp(c(6))]
@state sv6 = sv6(-1) + [var = exp(c(7))]
@state sv7 = sv7(-1) + [var = exp(c(8))]

@mprior SVEC0
@vprior SVAR0

When I hit "estimate" a message error appears : "Initial state variance prior "SVAR0" is not defined or is not a Sym object"

I don't understand, I followed the step of the manual guide to define SVEC0 and SVAR0. In my case, SVAR0 has to be a matrix 7x7 full of zeros...

I don't know if someone could run this workfile and tell me if it works ? I updated Eviews 7 but still the same problem and if I don't specify SVAR0, I get : "Missing value found in state variance matrix"

Please help me :lol:

Thank you, I really appreciate your help!
Attachments
kf.wf1
(29.19 KiB) Downloaded 428 times

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Running Kalman filter with initial data

Postby trubador » Fri Aug 06, 2010 6:41 am

Initial state variance matrix (SVAR0 in your case) has to be a sym object not an ordinary matrix. If you have initial values for state variances as a vector (e.g. vars), then you can create a symmetric matrix as follows:

Code: Select all

sym SVAR0 = @makediagonal(vars)

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Re: Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 6:55 am

Thank you for your answer.

If I'm right, I have to create a Vector with initial values of the variance (zeros in my case) and then insert the the code you gave me instead of "SVAR0" ?

My last row of code will be : @vprior sym SVAR0 = @makediagonal(vars) ?

Thank you again

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Running Kalman filter with initial data

Postby trubador » Fri Aug 06, 2010 7:06 am

The code is for generating the symmetric matrix outside (in the command window). Do not place it into State Space object. You do not have to change the specification of your state space, since the only problem is the type of your SVAR0 matrix.

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Re: Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 7:08 am

I'm sorry, I did what you told me but I still get the error message "Missing value found in state variance matrix"...

Can you help me ? I'm really lost.

Thank you very much

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Running Kalman filter with initial data

Postby trubador » Fri Aug 06, 2010 7:26 am

Initialize the coefficents as well and fix them at the start of each estimation. Otherwise, in each estimation EViews will use the stored values in the coefficient vector from the previous estimation. Add the following line to State Space specification below your code:

Code: Select all

param c(1) .0 c(2) .0 c(3) .0 c(4) .0 c(5) .0 c(6) .0 c(7) .0 c(8) .0


Of course, you can assign different values if you have a priori information.

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Re: Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 8:46 am

I'm truly sorry but I get the same error message... "Missing value found in state variance matrix". Here is my code :

@signal CON_AR = sv1*BONDS + sv2*CMDTY + sv3*CREDITS + sv4*EMMB + sv5*EMME + sv6*SP + sv7*USD + [var = exp(c(1))]

@state sv1 = sv1(-1) + [var = exp(c(2))]
@state sv2 = sv2(-1) + [var = exp(c(3))]
@state sv3 = sv3(-1) + [var = exp(c(4))]
@state sv4 = sv4(-1) + [var = exp(c(5))]
@state sv5 = sv5(-1) + [var = exp(c(6))]
@state sv6 = sv6(-1) + [var = exp(c(7))]
@state sv7 = sv7(-1) + [var = exp(c(8))]

@mprior svec0
@vprior svar0

param c(1) .0 c(2) .0 c(3) .0 c(4) .0 c(5) .0 c(6) .0 c(7) .0 c(8) .0

and I computed sym SVAR0 = @makediagonal(vars) in the command window as you told me...

I'm sorry but could you check if it works on your system ?

Thank you trubador
Attachments
kf.wf1
(29.29 KiB) Downloaded 472 times

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Running Kalman filter with initial data

Postby startz » Fri Aug 06, 2010 9:04 am

I opened the workfile, double-clicked on SS01, and hit Estimate. It ran with no problem, although it did report WARNING: Singular covariance.

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Re: Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 9:09 am

I don't understand why it doesn't work ?!?

Can I abuse of your kindness and ask you the results you get ? Could you post them ?

Thank you very much

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Running Kalman filter with initial data

Postby startz » Fri Aug 06, 2010 9:21 am

Glad to lend a bit of a hand. Here's the estimate using EViews 7.1 and the latest update.
Capture.JPG
Capture.JPG (114.28 KiB) Viewed 13325 times

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Re: Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 9:30 am

Thank you very much for all your help!

Have a nice day

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Running Kalman filter with initial data

Postby startz » Fri Aug 06, 2010 9:36 am

king_luca wrote:Thank you very much for all your help!

Have a nice day

I wish I could be more helpful.

You may have already answered this, but are you using the most uptodate version of EViews?

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Re: Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 9:54 am

Yes I do, I updated it... But the workfile seems to work on the system of a friend of mine.

However, I'd have one last question : how can I specify that my 7 regressors must sum to 1 ?

Thank you again for your help!

king_luca
Posts: 22
Joined: Thu Aug 05, 2010 2:28 am

Re: Running Kalman filter with initial data

Postby king_luca » Fri Aug 06, 2010 10:18 am

I have 2 other, maybe silly, questions : are the results of the estimation for the coefficient c(1) to c(8) in percent ? and how can I constraint the coefficient c(1) to c(8) to be positiv ?

Thank you for all your help
Last edited by king_luca on Fri Aug 06, 2010 10:32 am, edited 2 times in total.

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Running Kalman filter with initial data

Postby startz » Fri Aug 06, 2010 10:19 am

king_luca wrote:Yes I do, I updated it... But the workfile seems to work on the system of a friend of mine.

However, I'd have one last question : how can I specify that my 7 regressors must sum to 1 ?

Thank you again for your help!

If you mean the coefficients on the variables, replace SV7 with (1-SV1-SV2-SV3-SV4-SV5-SV6)


Return to “Estimation”

Who is online

Users browsing this forum: No registered users and 16 guests