Page 1 of 1

Daily to weekly conversion

Posted: Tue Oct 06, 2020 9:05 am
by BT454
Hi all,
I'm attempting to convert daily data, to weekly data (week starting friday). However, no matter how I structure my weekly data workfile (week starting monday, friday, etc), it treats the data as if the week is starting on a Tuesday.
I have attached the relevant workfiles and prg to this post.
The conversion is towards the bottom of the PRG, before the stop command.
Any help is appreciated.
Thanks!
Bob

Re: Daily to weekly conversion

Posted: Tue Oct 06, 2020 9:45 am
by EViews Gareth
Starting the week on a Friday seems to work:

Code: Select all

close @wf wfopen sql_demand wfcreate(wf=weekly2, page=w) w 2019/10/04 2020/10/20 copy sql_demand::data\dindmclo weekly2::w\dindmclo wfselect sql_demand pageselect data smpl if @weekday = 4 'only show thursday's group g @movav(dindmclo, 7) ' display 7 day moving average (i.e. the weekly average, starting on a friday) show g wfselect weekly2 show dindmclo

Re: Daily to weekly conversion

Posted: Tue Oct 06, 2020 10:26 am
by BT454
Thank you for your reply. Your snippet of code does show that it works. However, the prg I included does not.
If I use the default starting day (or set it to friday), the dates for the week and the average do not match your code.
Could it have something to do with my smpl setting in creating the weekly wf? That seems to be the only place where our code differs.
Thanks,
Bob

Re: Daily to weekly conversion

Posted: Tue Oct 06, 2020 10:38 am
by EViews Gareth
What do you mean by sample setting?

Re: Daily to weekly conversion

Posted: Tue Oct 06, 2020 10:47 am
by BT454
If I copy and paste "2019/10/04 2020/10/20" as the smpl period in my code it works fine.
If I leave my string reference %start %end, the averages are thrown off.
I just recoded the prg so that those strings are declared as:
%start = @str(@dateval(@date)-364)
%end = @str(@dateval(@date)+14)

The issue is with the first part of the smpl period.
wfcreate(wf=weekly) w 2019/10/4 %end yield the correct average
wfcreate(wf=weekly) w %start %end yield an incorrect average
in this instance, %start = "2020/10/8". I'm assuming the truncated first week is throwing off the entire conversion. Does this make sense?
Thanks,
Bob

Re: Daily to weekly conversion

Posted: Tue Oct 06, 2020 11:07 am
by EViews Gareth
Ah, that's not a sample.


But, when you create a weekly workfile the start date specifies the day of the week the workfile begins on. So if you want your weeks to start on a Friday, you have to use a start date of a Friday.

Re: Daily to weekly conversion

Posted: Wed Oct 07, 2020 9:21 am
by BT454
This is very helpful. Thank you!