Page 1 of 1

If statement based on dates

Posted: Thu Oct 16, 2014 7:16 am
by vytama
Hello, I want to run 3 separate equations in a program based on what current month is. Here is what I have on paper:

If month_today(m10)=m10(october), m7(July), m4(april) or m1(january)
then equation1.ls c indicator1(-1) indicator2(-1)

if month_today=m11, m8, m5 or m2
then equation2.ls c indicator1(-2) indicator2(-2)

I am struggling with the first line where I am comparing today's month with selected months.
Is it possible to put this in a code? I would appreciate your help. Eviews 8 user. Thank you

Re: If statement based on dates

Posted: Thu Oct 16, 2014 7:19 am
by startz
something like

Code: Select all

smpl if @month= 10 or @month=7 or @month=4 or @month=1

Re: If statement based on dates

Posted: Tue Nov 18, 2014 12:02 pm
by vytama
Hi,

I've tried the suggestion above with smpl, but it selects only the months specified(for instance, @month=10 calculates only 10th month for each year)

As an alternative, I am trying running the program below but i get error : @month is an illegal or reserved name:

if @month = 10 or @month = 7 or @month = 4 then
series a=@pcy(BRGDP___G)
else
series aa=@pca(BRGDP___G)
endif

What am I missing? Thanks, Eviews 8

Re: If statement based on dates

Posted: Tue Nov 18, 2014 12:34 pm
by EViews Gareth
I don't understand what you're trying to do. Or, alternatively, I don't understand why smpl didn't work.

Re: If statement based on dates

Posted: Tue Nov 18, 2014 2:24 pm
by vytama
I guess i was thinking more in excel logic.

If I use smpl - it gives me an error that "else is found outside of loop or if statement". if is not in blue font as then, else and endif are:

smpl if @month= 10 or @month = 7 or @month = 4 or @month = 1 then
equation ols_AA.ls equation1.ls c indicator1(-1) indicator2(-1)
else
smpl if @month= 2 or @month = 5 or @month = 8 or @month = 11 then
equation ols_AB.ls equation1.ls c indicator1(-2) indicator2(-2)
else
equation ols_AC.ls equation1.ls c indicator1(-3) indicator2(-3)
endif
endif
What am I missing/misunderstanding in this IF statement? Thank you.

Re: If statement based on dates

Posted: Tue Nov 18, 2014 2:34 pm
by EViews Gareth
You can't use an if statement like that. If statements evaluate scalars. You aren't evaluating a scalar, you're evaluating a series. You use smpl expressions to evaluate series.

If you can try to explain, in words, what you're trying to achieve, we can probably tell you how to achieve it.

Re: If statement based on dates

Posted: Tue Nov 18, 2014 3:57 pm
by vytama
sorry for the confusion.
I want to run 3 equations depending on a current month: if today's month=11 or 8 or 5 or 2-
run equation equation ols_AA.ls equation1.ls c indicator1(-1), indicator2(-1)

If current month = 10 or 7 or 4 or 1 -
run equation quation ols_AB.ls equation1.ls c indicator1(-2) indicator2(-2)

otherwise run equation equation ols_AC.ls equation1.ls c indicator1(-3) indicator2(-3)


so today is November and I would need to run equation AA, next month is December - I would need to run the third equation AC. Then January comes and would need equation AB and so on

I hope this makes it a bit more clear. Thank you

Re: If statement based on dates

Posted: Tue Nov 18, 2014 4:09 pm
by startz
something like

Code: Select all

scalar currentMonth = @datepart(@now,"mm") if currentMonth = 11 or currentMonth = 8 or currentMonth = 5 or currentMonth = 2 then ls a else if etc

Re: If statement based on dates

Posted: Tue Nov 18, 2014 4:15 pm
by EViews Gareth
Startz's answer will work well.

I should apologise for the confusion - my initial, and all following reading, of your question read "current month" as "the month of the current observation", and not "the month the world is currently in". Any normal person would interpret it the way you meant it. I've just been stuck in data land too much.

Re: If statement based on dates

Posted: Wed Nov 19, 2014 5:23 am
by vytama
Gareth, no worries. My fault too - for not specifying that I was looking for a "real" date, not observation. I will Startz suggestion later today. Thank you for your help.