Page 1 of 1

Problem with if statement

Posted: Mon Sep 12, 2011 7:01 am
by miksterz1
I am having a problem with a ridiculously routine task. I am trying to execute an if statement of the following type

Code: Select all

series check = @isna(forex) if check=1 then series m = 1 endif
I don't actually want to create a series 'm' that equals 1, but have shown that for simplicity. When I run this code, eviews does not create the series 'm' at all. The variable 'check' is a dummy so it always equals either 0 or 1. However. within the if statement, eviews doesn't seem to be reading the 1s in the series. If I add another line of code 'else series m = 0' it does create a series m but it always equals 0.

So basically, for some reason eviews thinks the condition is never true when in fact it is true in many periods.

Re: Problem with if statement

Posted: Mon Sep 12, 2011 7:25 am
by startz
I am having a problem with a ridiculously routine task. I am trying to execute an if statement of the following type

Code: Select all

series check = @isna(forex) if check=1 then series m = 1 endif
I don't actually want to create a series 'm' that equals 1, but have shown that for simplicity. When I run this code, eviews does not create the series 'm' at all. The variable 'check' is a dummy so it always equals either 0 or 1. However. within the if statement, eviews doesn't seem to be reading the 1s in the series. If I add another line of code 'else series m = 0' it does create a series m but it always equals 0.

So basically, for some reason eviews thinks the condition is never true when in fact it is true in many periods.
The if statement doesn't work that way in EViews, which can be confusing. Try

Code: Select all

series m = @recode(check,1,0)

Re: Problem with if statement

Posted: Mon Sep 12, 2011 7:33 am
by miksterz1
Thanks, startz. That did work, though I probably should have been more specific about what I am trying to do (I think your solution only tackles this particular example).

I want to create a conditional statement that says when forex=na, replace the na with whatever the last actual value was of forex.

The way I tried doing this is to create the dummy 'check' which equals 1 when forex=na and then refer to it.

Re: Problem with if statement

Posted: Mon Sep 12, 2011 8:10 am
by EViews Gareth

Code: Select all

forex = @recode(forex=na, forex(-1),forex)

Re: Problem with if statement

Posted: Mon Sep 12, 2011 11:03 am
by miksterz1
Thanks, Gareth!