Problems with EWISE statement

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
TedKury
Posts: 7
Joined: Tue Nov 14, 2006 8:38 am

Problems with EWISE statement

Unread post by TedKury »

I'm using an EWISE statement in a procedure and it's not working properly. I'm wondering if anyone has any suggestions.

EWISE AUX1(I) = (2/LAGS * (LAGS-I)) ** 2

AUX1 is a local real vector, dim LAGS-1. When LAGS=2, then AUX1 has just one element, 1. That works fine. If I set LAGS to anything else, like 3 or 4, the vector contains all zeros.

Any ideas why?
TomM
Posts: 20
Joined: Tue Oct 24, 2006 3:34 pm

Unread post by TomM »

The problem is that you are doing integer division here:

2/LAGS

Integer division returns an integer result, with any remainder truncated. So, if LAGS = 3, you are getting:

2/3 = 0.66667

which truncates down to zero.

Assuming you want a fractional result, you need to make one or both terms real rather than integer. Easiest way is to add a decimal to the "2". For example:

EWISE AUX1(I) = (2.0/LAGS * (LAGS-I)) ** 2

Tom Maycock
Estima
Tom Maycock
Estima

support@estima.com
TedKury
Posts: 7
Joined: Tue Nov 14, 2006 8:38 am

Unread post by TedKury »

Ugh. I can't believe I overlooked that.

I also wanted to say that I can't get access to e-mail lists at work, so I think that this forum is a great service.

Thanks, Tom.
Post Reply