Avoiding divide by zero errors

For questions regarding programming in the EViews programming language.

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

GeoffC
Posts: 10
Joined: Tue Sep 14, 2010 12:23 am

Avoiding divide by zero errors

Postby GeoffC » Fri Oct 08, 2010 9:34 am

I'm trying to find a way of avoiding errors when dividing one series by another, when the latter series may contain zero values.

I would expect the @recode function to be the answer, but if I run this sample program:

Code: Select all

series x = 2 x(1) = 0 series y = 1 series z = @recode(x=0,na,y/x)
I still get a divide by zero error, although the series Z is correctly computed.

The only ways round it that I have found are either to run the program with the maximum errors option set to some suitable value >1, which risks masking other errors, or to write an if statement using the @elem function to test each value of x in turn, which is potentially slow and inelegant.

Is there a better solution? I'm using EViews 7.

Thanks
Geoff

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

Re: Avoiding divide by zero errors

Postby EViews Gareth » Fri Oct 08, 2010 10:09 am

Code: Select all

series z = y/@recode(x=0,na,x)

GeoffC
Posts: 10
Joined: Tue Sep 14, 2010 12:23 am

Re: Avoiding divide by zero errors

Postby GeoffC » Sat Oct 09, 2010 3:20 am

Many thanks.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests