Problem with if statement

For questions regarding programming in the EViews programming language.

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

miksterz1
Posts: 33
Joined: Fri May 20, 2011 5:20 am

Problem with if statement

Postby miksterz1 » Mon Sep 12, 2011 7:01 am

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.

startz
Non-normality and collinearity are NOT problems!
Posts: 3796
Joined: Wed Sep 17, 2008 2:25 pm

Re: Problem with if statement

Postby startz » Mon Sep 12, 2011 7:25 am

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)

miksterz1
Posts: 33
Joined: Fri May 20, 2011 5:20 am

Re: Problem with if statement

Postby miksterz1 » Mon Sep 12, 2011 7:33 am

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.

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

Re: Problem with if statement

Postby EViews Gareth » Mon Sep 12, 2011 8:10 am

Code: Select all

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

miksterz1
Posts: 33
Joined: Fri May 20, 2011 5:20 am

Re: Problem with if statement

Postby miksterz1 » Mon Sep 12, 2011 11:03 am

Thanks, Gareth!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests