Week number code

For questions regarding programming in the EViews programming language.

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

BT454
Posts: 44
Joined: Wed Aug 02, 2017 6:07 am

Week number code

Postby BT454 » Fri Mar 22, 2019 11:03 am

Good afternoon,
I'm attempting to write some code to compare weekly frequency data, over the span of several years (i.e .comparing the third week of data for year x, to the third week in year y, to the third week in year z). I thought about just using lags of (-52), but some years have 53 weeks.
Is there a way to do this?
Thanks,
Bob

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

Re: Week number code

Postby EViews Gareth » Fri Mar 22, 2019 11:16 am

Welcome to the horrors of working with weekly data.

If you can describe mathematically how you'd like to do the comparisons, we can probably tell you how to do it in EViews.
Follow us on Twitter @IHSEViews

BT454
Posts: 44
Joined: Wed Aug 02, 2017 6:07 am

Re: Week number code

Postby BT454 » Fri Mar 22, 2019 11:28 am

Thank you very much in advance for the help.
For starters, I need to create 5 year average series for each week number of the year.
I.e. lagging five year average of series x, in week 10 of 2019 = (x_week10 _2018 + x_week10_2017 + x_week10_2016 + x_week10_2015 + x_week10_2014)/5
Does that help clarify?

I thought about creating a series that assigns the week number to the week ending date using excel, and importing it to eviews, but I'm not sure how I'd use it to cross reference against other series.
Thanks again,
Bob

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

Re: Week number code

Postby EViews Gareth » Fri Mar 22, 2019 11:36 am

But how do you define a week number?

What is week 10 in 2019? What is week 10 in 2018? Etc...
Follow us on Twitter @IHSEViews

BT454
Posts: 44
Joined: Wed Aug 02, 2017 6:07 am

Re: Week number code

Postby BT454 » Fri Mar 22, 2019 11:58 am

Good question.
This actually differs depending on what the data is, but for this example we'd focus on week ending Saturday (some other data is week ending Friday).
i.e. week 10 in 2019 ends Saturday March, 9, so Sunday March 3 - Saturday March 9 would all be days included in week 10 of 2019.
In 2018 week 10 would start on Sunday, March 4 and run through Saturday, March 10.
Does this help?
Thanks,
Bob

EViews Matt
EViews Developer
Posts: 358
Joined: Thu Apr 25, 2013 7:48 pm

Re: Week number code

Postby EViews Matt » Fri Mar 22, 2019 3:09 pm

Hello,

Since you have weekly data (dated I assume), for practical purpose is not the simple definition that week 1 is the first observation of the year, week 2 is the second observation of the year, etc., sufficient? This definition matches how EViews displays the date for each week by default (the earliest date within the week represented by the observation, implicitly interpreting "... observation of the year" to mean "... observation beginning in the year").

BT454
Posts: 44
Joined: Wed Aug 02, 2017 6:07 am

Re: Week number code

Postby BT454 » Sat Mar 23, 2019 6:35 am

yes, that is correct. Week one is the first week, week two is the second week, so on and so forth. Where those weeks start and end are at times important (although it may not matter right now, but for instance NOAA HDD/CDD weekly data has a week ending on Saturday, EIA weekly storage data has a week ending on Friday morning, but as long as I can pull that weekly data into eviews and have it be able to recognize which week of the year it is (1-52, or 53 in certain instances) that is at least enough to get up and running.
Thank you very much,
Bob

EViews Matt
EViews Developer
Posts: 358
Joined: Thu Apr 25, 2013 7:48 pm

Re: Week number code

Postby EViews Matt » Mon Mar 25, 2019 10:39 am

How about this:

Code: Select all

series weekid = @ceiling(@datepart(@date, "ddd") / 7)
series oneyearlag = -@ceiling(@datepart(@dateadd(@date, -weekid, "w"), "ddd") / 7)
series twoyearlag = oneyearlag + oneyearlag(oneyearlag)
series threeyearlag = twoyearlag + oneyearlag(twoyearlag)
series fouryearlag = threeyearlag + oneyearlag(threeyearlag)

You can then calculate a five-year average for all* weeks as:

Code: Select all

series y = (x + x(oneyearlag) + x(twoyearlag) + x(threeyearlag) + x(fouryearlag)) / 5

*The one caveat is that the above doesn't work for the 53rd week of the year, but that would need to be a special case anyway.

BT454
Posts: 44
Joined: Wed Aug 02, 2017 6:07 am

Re: Week number code

Postby BT454 » Mon Mar 25, 2019 2:14 pm

Thanks!
It looks like this did the job quite well.
Bob

BT454
Posts: 44
Joined: Wed Aug 02, 2017 6:07 am

Re: Week number code

Postby BT454 » Tue Mar 26, 2019 1:27 pm

I was wrong about that. Never mind my previous post, and thanks again!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 6 guests