On Wed, 21 May 2014, Sven Schreiber wrote:
Next I would like to convert the workfile from 7-days-daily to
5-days-daily, i.e. remove the empty (=missings) weekends obs, but this
doesn't seem to be easy to do. (Note that removing all missing obs is
not equivalent, because that also eliminates other holidays, which is
another topic. Also I know I could use 'join' together with the source
csv file to do that, but I think it should be easier than that, no?)
This should do what you want: not the most elegant approach, but IMO quite
clear and general. The only thing I don't like very much is the necessity
to go through a temporary file, which I find quite ugly. Allin, we talked
a bit about the possibility of having a "forever" option to the smpl
command, which would effectively eliminate certain rows from a dataset (so
that operations like "keep" and "drop" in Stata) become quite easy.
What
do you think?
<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
# use a tmpfile
store @dotdir/tmp.gdtb
clear
open @dotdir/tmp.gdtb --quiet
# ta-daaa!
setobs 5 2014-04-01
print x -o
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------