Page 1 of 1

Validating series type

Posted: Tue Jan 31, 2017 10:07 am
by BigD
Hi,

I'm wondering if there's a way to validate a series type. I'm thinking of checking whether a series is numerical or alpha. And if it is alpha, I would add an error message in a table I'm creating such as "This is an alpha series" and have the loop move to the next series before calculating the percentage difference (as that will result in an error).

Here's what I have so far:

Code: Select all

'create table + setup !row = 2 table aresults aresults(1, 1) = "Series" aresults(1, 2) = "Year" aresults(1, 3) = "Old Value" aresults(1, 4) = "New Value" aresults(1, 5) = "% Difference" aresults(1, 6) = "Comments" ''''''''''''''''''''''''''''''''''''''''''''''' ' LOOP ' ''''''''''''''''''''''''''''''''''''''''''''''' 'loops through series list for !j=1 to chgename.@count %seriesnam = chgename.@seriesname(!j) 'check if series is an alpha series if {%seriesnam}.@type == "alpha" then 'comments aresults(!row, 6) = "Series is an alpha series." 'increment row !row = !row + 1 'move to next series %seriesnam = chgename.@seriesname(!j + 1) endif 'calculates percentdiff for the last 10 years smpl @last-9 @last %seriesnam = chgename.@seriesname(!j) series b{%seriesnam} = @abs(({%seriesnam}_01 - {%seriesnam}) / (({%seriesnam} + {%seriesnam}_01) / 2)) * 100 ...
Thanks!

Re: Validating series type

Posted: Tue Jan 31, 2017 10:16 am
by EViews Gareth
You're doing it correctly. The only thing to watch out for is that @type returns its results in caps, so you have to check whether it matches "ALPHA", not "alpha".

Re: Validating series type

Posted: Tue Jan 31, 2017 10:28 am
by BigD
I see, I've changed it to

Code: Select all

if {%seriesnam}.@type == "ALPHA" then ...
but it didn't work. The percent difference calculation still went. I even tried @detailedtype. Is my increment to skip alpha series for the calculation incorrect?

Re: Validating series type

Posted: Tue Jan 31, 2017 10:35 am
by EViews Gareth
It is incorrect.

First off, there is no == in EViews, just a =.


Secondly:

Code: Select all

%seriesnam = chgename.@seriesname(!j + 1) endif 'calculates percentdiff for the last 10 years smpl @last-9 @last %seriesnam = chgename.@seriesname(!j) series b{%seriesnam} = @abs(({%seriesnam}_01 - {%seriesnam}) / (({%seriesnam} + {%seriesnam}_01) / 2)) * 100
You change the %seriesnam inside the if statement, but then you change it back again outside. Either increase !j inside the if statement, or, more easily, put all the series based stuff inside an else:

Code: Select all

if {%seriesnam}.@type = "ALPHA" then 'comments aresults(!row, 6) = "Series is an alpha series." 'increment row !row = !row + 1 else 'calculates percentdiff for the last 10 years smpl @last-9 @last %seriesnam = chgename.@seriesname(!j) series b{%seriesnam} = @abs(({%seriesnam}_01 - {%seriesnam}) / (({%seriesnam} + {%seriesnam}_01) / 2)) * 100 '.... !row = !row+! endif

Re: Validating series type

Posted: Tue Jan 31, 2017 10:54 am
by BigD
Oh right. Forgot there's an else statement option and mixed up == and =. Silly me.
However, it still doesn't work. Perhaps it is because the alpha series are skipping over the condition?
The error I get goes like "Numeric operator applied to string data in "SERIES B{%SERIESNAM} = @ABS((GDPB_01 - GDPB) / ((GDPB + GDPB_01) / 2)) * 100".
Which means that the alpha series didn't get skipped.

Re: Validating series type

Posted: Tue Jan 31, 2017 10:57 am
by BigD
Oh nvm. My brain is probably dead today. I used the wrong {%seriesnam} for the condition. This was for the old data (which are all numerical). {%seriesnam}_01 is for new data which are the ones I'm testing for.

Got it. Thank you so much!