Page 1 of 1
Log of non-positive number
Posted: Tue Apr 16, 2013 8:54 pm
by bigmonty
We are running a model where the model stops running spitting a error message saying that " log of non-positive number". After tracing the variables, we found that one of the variables becoming negative for which the log can not be created. As a result, the model stopped running at this point. I was wondering is there any way to incorporate in the model an if else statement so that whenever any variable encounters a negative number it is forced to a positive no. Like the following statement:
if x<0 then
x=.005
else
x=x
endif
I tried to put this in the model text but it generated error.
Any help on this would be highly appreciated.
Re: Log of non-positive number
Posted: Tue Apr 16, 2013 9:12 pm
by EViews Gareth
Use the @recode function
Re: Log of non-positive number
Posted: Tue Apr 16, 2013 9:51 pm
by bigmonty
Thanks a lot for your response. I am still finding it difficult to implement the code.
Let me elaborate a bit. One of the variables, say, ygdp has become negative. So, I would put the code in the model text
@recode((ygdp<0),(ygdp=.005),(ygdp=ygdp))
Basically, I am trying to tell the model that if ygdp<0, then put ygdp=.005 else ygdp stays as ygdp.
But it is generating syntax error. Any idea, what went wrong?
Re: Log of non-positive number
Posted: Tue Apr 16, 2013 9:55 pm
by EViews Gareth
Code: Select all
ygdp = @recode(ygdp<0, ygdp, 0.005)
Re: Log of non-positive number
Posted: Tue Apr 16, 2013 10:03 pm
by bigmonty
Let expand on my problem a bit more.
Code: Select all
YGDP = CP + IP + G + YEXP - YIMP
@recode(ygdp<0 , .005 , ygdp)
YD = YGDP - IT + TR + SUB
NYD = YD + REMD * exr
What you see above is the text view from a model object. I can not write ygdp=@recode(ygdp<0 , .005 , ygdp) because we can not have the same
endogenous variable defined twice in the same model. But the above formulation is generating syntax error. Actually this is one I first tried and then resort to the second one which I mentioned in my earlier post. Any ideas?
Re: Log of non-positive number
Posted: Wed Apr 17, 2013 5:33 am
by EViews Gareth
Code: Select all
temp = CP + IP + G + YEXP - YIMP
@identity ygdp = @recode(temp<0 , .005 , temp)
YD = YGDP - IT + TR + SUB
NYD = YD + REMD * exr