Log of non-positive number

For questions regarding programming in the EViews programming language.

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

bigmonty
Posts: 7
Joined: Tue Jan 29, 2013 10:12 pm

Log of non-positive number

Postby bigmonty » Tue Apr 16, 2013 8:54 pm

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.

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

Re: Log of non-positive number

Postby EViews Gareth » Tue Apr 16, 2013 9:12 pm

Use the @recode function

bigmonty
Posts: 7
Joined: Tue Jan 29, 2013 10:12 pm

Re: Log of non-positive number

Postby bigmonty » Tue Apr 16, 2013 9:51 pm

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?

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

Re: Log of non-positive number

Postby EViews Gareth » Tue Apr 16, 2013 9:55 pm

Code: Select all

ygdp = @recode(ygdp<0, ygdp, 0.005)

bigmonty
Posts: 7
Joined: Tue Jan 29, 2013 10:12 pm

Re: Log of non-positive number

Postby bigmonty » Tue Apr 16, 2013 10:03 pm

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?

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

Re: Log of non-positive number

Postby EViews Gareth » Wed Apr 17, 2013 5:33 am

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests