string expression to numeric variable

For questions regarding programming in the EViews programming language.

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

AnnH
Posts: 22
Joined: Fri Mar 09, 2012 11:42 am

string expression to numeric variable

Postby AnnH » Mon Apr 16, 2012 10:15 am

Working on a program that was originally written in eviews 4, running in eviews 7.

For the following lines of code

%kda = %k + "dpp"
series {%k}dpp = d({%k})

I get the error message:
Can not assign string expression to numeric variable in "SERIES %KDPP = D(AMBER_0)

Where AMBER_0 is the variable name

I am simply trying to calculate the level change for each variable

Thank you.

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

Re: string expression to numeric variable

Postby EViews Gareth » Mon Apr 16, 2012 10:20 am

That should work:

Code: Select all

create u 100 series x=nrnd %k = "x" series {%k}dpp = d({%k})
No error, and series calculates correctly in EV72.

AnnH
Posts: 22
Joined: Fri Mar 09, 2012 11:42 am

Re: string expression to numeric variable

Postby AnnH » Fri Apr 20, 2012 7:42 am

It seems to work for 1 variable, but I am having trouble getting it to go through a list of variables as in this:

FOR !k = 3 to VarList1.@count
%k = VarList1.@seriesname(!k)
create u 100
series x=nrnd
%k = "x"
series {%k}dpp = d({%k})


When I run it, I get x and xdpp created, but then I get an error message for that says "VarList1 is not defined in "%K = VarList1.@SERIESNAME(4)"."


Thank you.

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

Re: string expression to numeric variable

Postby EViews Gareth » Fri Apr 20, 2012 7:48 am

That's because the "create" command creates a new workfile, and as soon as you're on a new workfile, varlist1 doesn't exist any more.

AnnH
Posts: 22
Joined: Fri Mar 09, 2012 11:42 am

Re: string expression to numeric variable

Postby AnnH » Fri Apr 20, 2012 7:56 am

ok, when I go to this:

FOR !k = 3 to VarList1.@count
%k = VarList1.@seriesname(!k)
series {%k}dpp = d({%k})
NEXT

I'm back to my error message of "Can not assign string expression to numeric variable in "SERIES {%K}DPP = D(AMBER_0))". Where AMBER_0 is the a variable name in my variable list

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

Re: string expression to numeric variable

Postby EViews Gareth » Fri Apr 20, 2012 8:11 am

Code: Select all

create u 100 series x1=nrnd series x2=nrnd series x3=nrnd series x4=nrnd series amber_0=nrnd group VarList1 x1 x2 x3 x4 amber_0 FOR !k = 3 to VarList1.@count %k = VarList1.@seriesname(!k) series {%k}dpp = d({%k}) NEXT

AnnH
Posts: 22
Joined: Fri Mar 09, 2012 11:42 am

Re: string expression to numeric variable

Postby AnnH » Fri Apr 20, 2012 8:51 am

Thank you. Sorry, I was missing brackets around a %k in the following code when I defined the variables so they were not numerical values.

FOR !k = 3 to VarList1.@count
%k = VarList1.@seriesname(!k)
GENR {%k}_0 = {%k}
NEXT

One more question, in the code above, when it makes the variable {%k}_0, it only put the value from {%k} into the last observation point.

For example, if %k is on a variable named AMBER, and AMBER has numerical values from 1999:Q1 through 2010:Q4, the above code generated AMBER_0, but only puts a value in the 2010:Q4 cell. The value in the 2010:Q4 cell matches the AMBER 2010:Q4 value, but all other cells from 1999:Q1 to 2010:Q3 have NA in them for AMBER_0, whereas AMBER has numbers.

Any ideas?

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

Re: string expression to numeric variable

Postby EViews Gareth » Fri Apr 20, 2012 8:55 am

Code: Select all

create q 1999q1 2010q4 series x1=nrnd series x2=nrnd series x3=nrnd series amber_0=nrnd group VarList1 x1 x2 x3 amber_0 FOR !k = 3 to VarList1.@count %k = VarList1.@seriesname(!k) GENR {%k}_0 = {%k} NEXT show amber_0


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests