On Wed, 21 May 2014, Riccardo (Jack) Lucchetti wrote:
[Re. Sven's wish to convert 7-day daily data, with nothing but NAs
for Saturdays and Sundays, into 5-day data]
This should do what [Sven wanted]: not the most elegant approach,
but IMO quite clear and general. [...]
<hansl>
nulldata 28
setobs 7 2014-04-01
x = normal()
print x -o
/*
trash weekends
*/
# first, construct a "weekend" dummy series
scalar y1 = $obsmajor[1]
scalar m1 = $obsminor[1]
scalar d1 = $obsmicro[1]
scalar wd1 = weekday(y1, m1, d1)
series wd = time + wd1 - 1
series we = (wd%7)==6 || (wd%7)==0
# clear periodicity
setobs 1 1
smpl we==0 --restrict
[...and then it's pretty simple]
</hansl>
Nicely done! But I note that it's a bit of a struggle since (up till
now) the weekday() function has only accepted scalar arguments. In
today's CVS I've "upgraded" this via our usual overloading approach:
you can now use series instead of scalars with weekday(). The
relevant portion of the above could then read:
<hansl fragment="true">
# construct a "weekend" dummy series
series wday = weekday($obsmajor, $obsminor, $obsmicro)
series weekend = wday == 6 || wday == 0
</hansl>
As a general comment, I'd say it's pretty uncommon to have to do
this sort of thing: almost all 5-day daily data does not include
weekends stuffed with NAs. So while gretl should be able to deal
with it, I don't think we have to go to great lengths to make it a
unitary ("one stop shopping") operation.
Allin