Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: repeated weeks in time series


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: repeated weeks in time series
Date   Wed, 7 May 2003 12:50:45 +0100

Metcalfe, Paul
>
> I would like to point out what I think is a glitch in stata
> regarding the
> -week- function.  In my data, two dates that are a week
> apart were assigned
> to the same week by stata's -week- function.  My code runs
> as follows:
>
> . gen year=year(date)
> . gen week=week(date)
> . gen wk=yw(year,week)
> . format wk %tw
> . tsset wk, w
> repeated time values in sample
> r(451);
>
> further inspection reveals that (part of) my data looks like:
>
> date		year	week	wk
> 09dec1996	1996	50	1996w50
> 16dec1996	1996	51	1996w51
> 23dec1996	1996	52	1996w52
> 30dec1996	1996	52	1996w52
> 06jan1997	1997	1	1997w1
>
> ie, stata has assigned two dates that are a week apart to
> the same week.
>
> The range of the week function is 1 to 52, however, maybe
> it ought to be 1
> to 53 to avoid this issue? Or maybe the first week of the
> year should start
> on the monday prior to the turn of the year? eg Monday
> 26/12/1996 = first
> day of week 1, 1997, etc. Or alternatively, Monday 3/1/1997
> = first day of
> week 1, 1997 and Sunday 2/1/1997 = last day of week 52, 1996.
>
> Maybe someone could suggest an alternative (better) code
> than mine given the
> way stata currently is? I have corrected my data manually
> so that the first
> week of the year starts on the monday prior to the turn of the year.
> However, this was longwinded.

Weeks are awkward, clearly. However,
your tentative proposal that the first week
of a year may start in the previous
calendar year is to my mind a case
of the cure being worse than the disease,
and I vote against it. I am not saying that
this may not be sensible for many projects,
merely that I don't think Stata should
do that automatically, especially as
it amounts to a change to fairly long-established
code.

Nick
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index