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
Week number code
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12315
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Week number code
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.
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
Re: Week number code
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
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

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12315
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Week number code
But how do you define a week number?
What is week 10 in 2019? What is week 10 in 2018? Etc...
What is week 10 in 2019? What is week 10 in 2018? Etc...
Follow us on Twitter @IHSEViews
Re: Week number code
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
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 Developer
 Posts: 391
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Week number code
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").
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").
Re: Week number code
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 (152, or 53 in certain instances) that is at least enough to get up and running.
Thank you very much,
Bob
Thank you very much,
Bob

 EViews Developer
 Posts: 391
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Week number code
How about this:
You can then calculate a fiveyear average for all* weeks as:
*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.
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 fiveyear 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.
Re: Week number code
Thanks!
It looks like this did the job quite well.
Bob
It looks like this did the job quite well.
Bob
Re: Week number code
I was wrong about that. Never mind my previous post, and thanks again!
Who is online
Users browsing this forum: No registered users and 7 guests