If statement based on dates

For questions regarding programming in the EViews programming language.

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

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

If statement based on dates

Postby vytama » Thu Oct 16, 2014 7:16 am

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

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

Re: If statement based on dates

Postby startz » Thu Oct 16, 2014 7:19 am

something like

Code: Select all

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

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: If statement based on dates

Postby vytama » Tue Nov 18, 2014 12:02 pm

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

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

Re: If statement based on dates

Postby EViews Gareth » Tue Nov 18, 2014 12:34 pm

I don't understand what you're trying to do. Or, alternatively, I don't understand why smpl didn't work.

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: If statement based on dates

Postby vytama » Tue Nov 18, 2014 2:24 pm

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.

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

Re: If statement based on dates

Postby EViews Gareth » Tue Nov 18, 2014 2:34 pm

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.

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: If statement based on dates

Postby vytama » Tue Nov 18, 2014 3:57 pm

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

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

Re: If statement based on dates

Postby startz » Tue Nov 18, 2014 4:09 pm

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

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

Re: If statement based on dates

Postby EViews Gareth » Tue Nov 18, 2014 4:15 pm

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.

vytama
Posts: 72
Joined: Wed Dec 19, 2012 11:05 am

Re: If statement based on dates

Postby vytama » Wed Nov 19, 2014 5:23 am

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.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests