How to use temporary variables in state space?

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

ohubert
Posts: 8
Joined: Thu Apr 21, 2022 2:21 am

How to use temporary variables in state space?

Postby ohubert » Thu May 19, 2022 12:59 am

Hi all,

I am trying to automate building a state space to avoid having numerous lines of code.

I want to estimate a relationship for a variable in levels or divided by GDP. I thus have created variables in level and divided by GDP. The structure of the names of the variables is convenient and allows easily selecting one or the other.

However, I do not manage to pass the names to the state space.


I paste below a mock example. I know that this model makes no sense, it is simply there to show what does not work.



Code: Select all

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

%stdgdp="gdp" ' shortcut for standarization by GDP: "" for not, "gdp" if yes

svector(2) longnames
longnames(1) = "series1" +%stdgdp  ' append the shortcut for whether it is standardized by GDP or not
longnames(2) = "series2" +%stdgdp
%varnames1=longnames(1)
%varnames2=longnames(2)


for !i=1 to 2 ' loop over the variables to create the GDP series
   %stringtemp2=longnames(!i) 'create temporary variable for the long
   series {%stringtemp2}gdp= {%stringtemp2}+!i*1000
next

' Not working state space
statespace locallevelbis ' Create the state space
locallevelbis.append @signal {%varnames1}=mu +[ename = e1, var = exp(c(1))]
locallevelbis.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevelbis.ml


I tried several forms:
longnames(1)
!longnames(1)
%longnames(1)
{longnames(1)}
{!longnames(1)}
{%longnames(1)}

and the same with varnames1, without success.

When using { }, I get the following error message:
Syntax error in "@SIGNAL =MU +[ENAME = E1, VAR =
EXP(C(1))]" in "LOCALLEVELBIS.ML" on line 75.
, which leads me to believe that the temporary variable varnames1 is empty. I confirm this by running the command:

Code: Select all

statusline {%varnames1}




Thanks a lot in advance.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to use temporary variables in state space?

Postby EViews Gareth » Thu May 19, 2022 7:43 am

I'm not sure I follow what you're doing.

The first element in longnames will be equal to:

Code: Select all

"series1gdp"


Then, inside your for loop, you store that value into %stringtemp2, then create a series with a name of whatever is inside %stringtemp2, followed by "gdp". Thus, the first time through your loop, the series you create will be called "series1gdpgdp".

You set that series equal to whatever is inside %stringtemp2. Thus the first time through the loop, that line is effectively:

Code: Select all

series series1gdpgdp = series1gdp + 1*1000


Which errors, since series1gdp doesn't exist.
Follow us on Twitter @IHSEViews

ohubert
Posts: 8
Joined: Thu Apr 21, 2022 2:21 am

Re: How to use temporary variables in state space?

Postby ohubert » Wed Jun 01, 2022 11:40 pm

Hi Gareth,

Thank you for spotting that error.

Suppose now that the code is the following:

Code: Select all

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

%stdgdp="gdp" ' shortcut for standarization by GDP: "" for not, "gdp" if yes

svector(2) shortnames
shortnames(1) = "short1"
shortnames(2) = "short2"

svector(2) longnames
longnames(1) = "series1" +%stdgdp  ' append the shortcut for whether it is standardized by GDP or not
longnames(2) = "series2" +%stdgdp
%varnames1=longnames(1)
%varnames2=longnames(2)


series series1gdp=series1 + 1000
series series2gdp =series2 + 2000

' Not working state space

statespace locallevelbis ' Create the state space
locallevelbis.append @signal {%varnames1}=mu +[ename = e1, var = exp(c(1))]
locallevelbis.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevelbis.ml


' Not working state space

%varnames11="series1"
statespace locallevelter ' Create the state space
locallevelter.append @signal {%varnames1}=mu +[ename = e1, var = exp(c(1))]
locallevelter.append @state mu=mu(-1) +[ename = e2, var = exp(c(2))]
locallevelter.ml



Still, locallevelbis or localleverter is unable to plug the variable name into the append command.


Am I doing something wrong or is Eviews unable to do this?


Thank you.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to use temporary variables in state space?

Postby EViews Gareth » Thu Jun 02, 2022 6:32 am

If I run you program, it runs without any errors, and both state spaces appear to estimate fine.
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 9 guests