Page 1 of 1

How do I set an initial coefficient value in a State Space object from a previously calculated scalar?

Posted: Wed May 18, 2022 2:45 am
by ohubert
Dear all,

when creating a state space object, how can I set an initial value for a coefficient of the state space which comes from an object that already exists in my workfile? I know how to set an initial value in a state space, but I would like to use outside information to help/accelerate the maximum likelihood estimation.

For instance, consider that a sensible value for a coefficient in the state space comes from a regression. How could I reference this coefficient when I declare param in the state space?

Consider the two models below (they make no sense, they are simply there for the example):

Code: Select all

wfcreate(wf=annual, page=myproject) a 1950 2005
genr series1=nrnd
genr series2= 0.9*series1(-1)+ 0.1*nrnd

' Working state space
statespace locallevel ' Create and estimate the state space with initial values
locallevel.append @signal series2=mu +[ename = e1, var = exp(c(1))]
locallevel.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevel.append param c(1) -7 c(2) -8.5
locallevel.ml


and Model 2:

Code: Select all

' Not working state space
equation leastsquare ' estimate mock regression
leastsquare.ls series2 c series2(-1)
scalar coef1=leastsquare.@coefs(1)

statespace locallevelbis ' Create the state space
locallevelbis.append @signal series2=mu +[ename = e1, var = exp(c(1))]
locallevelbis.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevelbis.append param c(1) -7 c(2) coef1 ' append the scalar as initial value
locallevelbis.ml


Is model 2 possible? If so, how should I reference coef1?

Thanks a lot in advance.

Re: How do I set an initial coefficient value in a State Space object from a previously calculated scalar?

Posted: Wed May 18, 2022 12:31 pm
by EViews Gareth

Code: Select all

' Not working state space
equation leastsquare ' estimate mock regression
leastsquare.ls series2 c series2(-1)
!coef1=leastsquare.@coefs(1)

statespace locallevelbis ' Create the state space
locallevelbis.append @signal series2=mu +[ename = e1, var = exp(c(1))]
locallevelbis.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevelbis.append param c(1) -7 c(2) {!coef1} ' append the scalar as initial value
locallevelbis.ml

Re: How do I set an initial coefficient value in a State Space object from a previously calculated scalar?

Posted: Thu May 19, 2022 12:01 am
by ohubert
Thank you.

However, I still get an error message:
!COEF1 is not a valid string or scalar name in "LOCALLEVELBIS.
APPEND PARAM C(1) -7 C(2) {!COEF1}" on line 59.



How can I solve this?


Thanks again.

Re: How do I set an initial coefficient value in a State Space object from a previously calculated scalar?

Posted: Thu May 19, 2022 7:36 am
by EViews Gareth
My bad, try it without the braces.

Code: Select all

' Not working state space
equation leastsquare ' estimate mock regression
leastsquare.ls series2 c series2(-1)
!coef1=leastsquare.@coefs(1)

statespace locallevelbis ' Create the state space
locallevelbis.append @signal series2=mu +[ename = e1, var = exp(c(1))]
locallevelbis.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevelbis.append param c(1) -7 c(2) !coef1 ' append the scalar as initial value
locallevelbis.ml

Re: How do I set an initial coefficient value in a State Space object from a previously calculated scalar?

Posted: Thu May 19, 2022 8:00 am
by ohubert
Hi Gareth,

Unfortunately, still not working:
Error in Param statement in "LOCALLEVELBIS.ML" on line 77.



Thanks.

Re: How do I set an initial coefficient value in a State Space object from a previously calculated scalar?

Posted: Thu May 19, 2022 8:04 am
by EViews Gareth
This program seems to run just fine for me:

Code: Select all

wfcreate(wf=annual, page=myproject) a 1950 2005
genr series1=nrnd
genr series2= 0.9*series1(-1)+ 0.1*nrnd

' Working state space
statespace locallevel ' Create and estimate the state space with initial values
locallevel.append @signal series2=mu +[ename = e1, var = exp(c(1))]
locallevel.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevel.append param c(1) -7 c(2) -8.5
locallevel.ml


' Not working state space
equation leastsquare ' estimate mock regression
leastsquare.ls series2 c series2(-1)
!coef1=leastsquare.@coefs(1)

statespace locallevelbis ' Create the state space
locallevelbis.append @signal series2=mu +[ename = e1, var = exp(c(1))]
locallevelbis.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevelbis.append param c(1) -7 c(2) !coef1 ' append the scalar as initial value
locallevelbis.ml

Re: How do I set an initial coefficient value in a State Space object from a previously calculated scalar?

Posted: Thu May 19, 2022 8:08 am
by ohubert
Thank you.