Converting daily data, week averages etc.

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason

Afhaalchinees
Posts: 3
Joined: Sat Jun 22, 2013 7:00 am

Converting daily data, week averages etc.

Postby Afhaalchinees » Sat Jun 22, 2013 7:30 am

Hi, normally I can solve my problems with answers from other topics, this time my problem is a bit too specific. I will try to be clear as possible.

I quote from "Good day Sunshine: Stock returns and the Weather":
'We calculate the average cloudiness value for each week of the year in each city,
and deseasonalize by subtracting each week’s mean cloudiness from each daily
mean. For example, we calculate the average value of SKCi,t for the first full
calendar week of the year for a particular city, taking an average of 80 values
(16 years times five days in the week). Then we subtract this mean from the city’s
daily SKCi,t values in the first week of each year. We denote the deseasonalized
value of SKC for city i on day t as SKC*it.The mean of SKC*it is close to zero, and it it
its global standard deviation is 2.19.'

I want to do the same for my variable. My dataset (sunshine hours) contains daily data from 1/03/1983 - 14/05/2013, weekdays. But I'm not sure how to do this...

My school runs Eviews 7. Hope someone can help, thanks for your attention!

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

Re: Converting daily data, week averages etc.

Postby EViews Gareth » Mon Jun 24, 2013 1:44 pm

The only tricky bit is setting the sample to be the first full week of the year.

Code: Select all

'create some data create d5 1983 @now series skc=0 'create a temporar series needed for the sample setting series startday = 7-@datepart(@datefloor(@date, "year"),"wdy") 'set sample to first full week of the year smpl if @datepart(@date,"ddd")>=startday and @datepart(@date,"ddd")<startday+7 'calculate average of the first week's data series skc_av = @mean(skc) 'calculate mean deviation series skc_md = skc-skc_av

Afhaalchinees
Posts: 3
Joined: Sat Jun 22, 2013 7:00 am

Re: Converting daily data, week averages etc.

Postby Afhaalchinees » Tue Jun 25, 2013 1:43 am

Thanks Mr. Gareth! It works, however I was probably a bit unclear.

I need to do this for every week of the year, the example in the quote was just to elaborate the statement of "We calculate the average cloudiness value for each week of the year in each city,and deseasonalize by subtracting each week’s mean cloudiness from each daily mean."

I tried to unsolve the codes, but my eviews knowledge is too poor (student).

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

Re: Converting daily data, week averages etc.

Postby EViews Gareth » Tue Jun 25, 2013 10:00 am

Code: Select all

'create some data create d5 1983 @now series skc=nrnd 'build up a series containing the "week number". The first complete week of the year will have a value of "1", the second complete week will have a value of "2" and so on. Incomplete weeks at the start of the year, or the end of the year, will have NA. series first_monday = 9-@datepart(@datefloor(@date, "year"),"wdy") 'day of year of first monday series week =@floor( (@datepart(@date,"ddd")-first_monday) / 7) +1 'week in year: numbering from week containing first monday 'na out any weeks whose Monday-Friday range straddles a year boundary smpl if @datepart(@date-(@weekday-1),"yyyy")<>@datepart(@date+(5-@weekday),"yyyy") week = na smpl if week<>na 'having created the weeknumber series, now we calculate the average by week. series skc_avg = @meansby(skc, week) 'and now calculate the deviation series skc_md = skc - skc_avg

Afhaalchinees
Posts: 3
Joined: Sat Jun 22, 2013 7:00 am

Re: Converting daily data, week averages etc.

Postby Afhaalchinees » Tue Jun 25, 2013 12:16 pm

Thanks! Works like a charm.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests