Validating series type

For questions regarding programming in the EViews programming language.

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

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Validating series type

Postby BigD » Tue Jan 31, 2017 10:07 am

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!

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

Re: Validating series type

Postby EViews Gareth » Tue Jan 31, 2017 10:16 am

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".

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Re: Validating series type

Postby BigD » Tue Jan 31, 2017 10:28 am

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?

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

Re: Validating series type

Postby EViews Gareth » Tue Jan 31, 2017 10:35 am

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

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Re: Validating series type

Postby BigD » Tue Jan 31, 2017 10:54 am

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.

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Re: Validating series type

Postby BigD » Tue Jan 31, 2017 10:57 am

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!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest