Existence testing

For questions regarding programming in the EViews programming language.

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

bhaupt
Posts: 25
Joined: Fri May 07, 2010 1:16 pm

Existence testing

Postby bhaupt » Thu Sep 02, 2010 8:21 am

For a lot of the programs I write, it would be beneficial to check to see if a Page or a Series (or really any object) already exists in my workfile. Instead I often find myself coding a much larger repetitive code section instead of being able to loop through a concise code template. I've scoured to look for an exists() test. I've finally set to write one. My concerns stem from interrupting the routine (via 'ESC') while in mid subroutine. If I interrupt at the wrong time, effectively I've allowed for an increase in errors which I might not catch.

Here's the other thing, if I try to call an error catching function on a series which does not exist, it should punt when the function call fails at the series declaration, effectively erroring on the error check.

This has *not* been tested since I'm still making sure that I've got the concept thought through well enough.

Any thoughts would be appreciated.

Code: Select all

' Using @errorcount and @maxerrs: get the current conditions and settings ' attempt to perform a null operation and confirm @errcount has not incremented ' return 1 if exists, return 0 if not subroutine local exist(series passed_series, scalar ret_val) %beg_err_ct = @errorcount %max_err_ct = @maxerrs %end_err_ct = @errorcount setmaxerrs = %max_err_ct + 1 genr temp_series = passed_series ret_val = 0 if %end_err_ct = %beg_err_ct then ' the set existed ret_val = 1 setmaxerrs = %max_err_ct -1 else 'the set did not exist. seterrcount = @errorcount - 1 setmaxerrs = %max_err_ct -1 endif endsub

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

Re: Existence testing

Postby EViews Gareth » Thu Sep 02, 2010 8:37 am

Nice idea, but using the @isobject function and %type data member is probably easier.

startz
Non-normality and collinearity are NOT problems!
Posts: 3797
Joined: Wed Sep 17, 2008 2:25 pm

Re: Existence testing

Postby startz » Thu Sep 02, 2010 8:38 am

Have you looked at @isobject()?

bhaupt
Posts: 25
Joined: Fri May 07, 2010 1:16 pm

Re: Existence testing

Postby bhaupt » Thu Sep 02, 2010 10:04 am

@isobject is exactly what I needed. It should clean up a few programs rather nicely.

svilen
Posts: 34
Joined: Wed Mar 18, 2009 5:59 am
Location: Sofia, Bulgaria
Contact:

Re: Existence testing

Postby svilen » Thu May 26, 2011 7:29 am

I would like to test if several series exist i.g. I know that the names of the series begin with "a_" or ends with "_0".
Something like this:

%check = "a_*"
@isobject(%check) -> "0" if there is no result, "1" if at least one exists

Any ideas would be appreciated.

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

Re: Existence testing

Postby EViews Gareth » Thu May 26, 2011 8:05 am

Use the @wlookup command. It will retrieve a list of all objects that match a criteria.

Jiri
Posts: 1
Joined: Tue Dec 03, 2019 9:06 am

Re: Existence testing

Postby Jiri » Tue Dec 03, 2019 9:24 am

Dear Gareth,

When using @isobject for testing for an existence of an equation in the workfile, Eviews tells me, that equation is invalid string argument. I cannot find any way how to change equation name into string. Please, could you help me, how to test if an equation exists?

I have, say, max 130 equations named eq1 eq2 … eq130, but some equations are missing (say eq7…). I need to store coefficients from these equations into a matrix using the program below. As the program stops at missing eq7, I tried to add the if condition, which is not working, unfortunately.

Thank you,
Jiri

matrix(130,12) coefs

for !i=1 to 130

if @isobject(eq{!i}) then

for !j=1 to eq{!i}.@ncoefs
coefs(!i,!j) = eq{!i}.@coef(!j)

endif

next
next

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

Re: Existence testing

Postby EViews Gareth » Tue Dec 03, 2019 9:27 am

Code: Select all

%name = "eq" + @str(!i) if @isobject(%name) then


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests