Page 1 of 1
string expression to numeric variable
Posted: Mon Apr 16, 2012 10:15 am
by AnnH
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.
Re: string expression to numeric variable
Posted: Mon Apr 16, 2012 10:20 am
by EViews Gareth
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.
Re: string expression to numeric variable
Posted: Fri Apr 20, 2012 7:42 am
by AnnH
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.
Re: string expression to numeric variable
Posted: Fri Apr 20, 2012 7:48 am
by EViews Gareth
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.
Re: string expression to numeric variable
Posted: Fri Apr 20, 2012 7:56 am
by AnnH
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
Re: string expression to numeric variable
Posted: Fri Apr 20, 2012 8:11 am
by EViews Gareth
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
Re: string expression to numeric variable
Posted: Fri Apr 20, 2012 8:51 am
by AnnH
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?
Re: string expression to numeric variable
Posted: Fri Apr 20, 2012 8:55 am
by EViews Gareth
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