Coding in sample ranges

For questions regarding programming in the EViews programming language.

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

ian.e.preston
Posts: 21
Joined: Mon Feb 23, 2015 1:06 pm

Coding in sample ranges

Postby ian.e.preston » Mon Feb 23, 2015 1:17 pm

I'm trying to produce rolling month ahead forecasts to test a model. The way I'm doing this is by looping over years and months and then setting the sample appropriately. The only way I've found to set my sample range seems really backwards and I'm hoping for a better way. My data is daily with a 5 day week and I'm using Eviews 7.

Code: Select all

for !y = 2001 to 2015 'forecast over all available years if !y=2015 then !mm=@datepart(@now,"mm") else !mm = 12 'Only forecast from a starting point in the present endif for !m = 1 to !mm 'loop through the months of the year 'For each month we produce a remainder of the month forecast and 3 months out %from = @datestr(@makedate(!y, !m, 15, "yyyy mm dd"),"mm/dd/yyyy") %to = @datestr(@makedate(!y, !m+3, "yyyy mm"),"mm/dd/yyyy") smpl %from %to
I'm not sure why I can't just use

Code: Select all

smpl @makedate(!y, !m, 15, "yyyy mm dd") @makedate(!y, !m+3, "yyyy mm")
But if I do that I get an illegal date. The same happens if I don't assign %first or %last to the @datestr and put it in directly. I'm guessing this is caused by some misunderstanding on my part of how Eviews interprets samples, but I can't figure it out from reading the documentation. If someone could provide a simpler way of coding this, and the intuition behind it I'd be grateful

As a simpler example, this also doesn't work:

Code: Select all

smpl 2003 @makedate(2004,"yyyy")
even though this does

Code: Select all

smpl 2003 2004

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

Re: Coding in sample ranges

Postby EViews Gareth » Mon Feb 23, 2015 4:16 pm

The smpl command does not accept dates. Rather it accepts string representations of dates.
Store the dates you want into program variables, then use those string variables in the smpl statement.

ian.e.preston
Posts: 21
Joined: Mon Feb 23, 2015 1:06 pm

Re: Coding in sample ranges

Postby ian.e.preston » Tue Feb 24, 2015 10:21 am

Ok, so why doesn't this work?

Code: Select all

smpl @datestr(@makedate(!y, !m, 15, "yyyy mm dd"),"mm/dd/yyyy") @datestr(@makedate(!y, !m+3, "yyyy mm"),"mm/dd/yyyy")
instead I have to use

Code: Select all

%from = @datestr(@makedate(!y, !m, 15, "yyyy mm dd"),"mm/dd/yyyy") %to = @datestr(@makedate(!y, !m+3, "yyyy mm"),"mm/dd/yyyy") smpl %from %to
I guess my issue is that this seems like a really unwieldy way of working with dates and samples. It works, but I feel like I'm doing things really inefficiently. Is there a better method I could be using to create my samples?

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

Re: Coding in sample ranges

Postby EViews Gareth » Tue Feb 24, 2015 10:54 am

I would probably do it the way you currently are.

Samples do allow simple observation addition.

So you could do:

Code: Select all

smpl 2005m1+11 2006m1+11
to mean December 2005 until December 2006, for example. You could possibly rewrite your loops to work in that format instead.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests