Page 1 of 1

Avoiding divide by zero errors

Posted: Fri Oct 08, 2010 9:34 am
by GeoffC
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

Re: Avoiding divide by zero errors

Posted: Fri Oct 08, 2010 10:09 am
by EViews Gareth

Code: Select all

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

Re: Avoiding divide by zero errors

Posted: Sat Oct 09, 2010 3:20 am
by GeoffC
Many thanks.