Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Charles Vellutini <charles.vellutini@ecopa.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Calendar weeks |

Date |
Wed, 15 Feb 2012 03:31:28 -0800 |

Many thanks Nick. That IS more elegant. -----Message d'origine----- De : owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] De la part de Nick Cox Envoyé : mercredi 15 février 2012 10:38 À : statalist@hsphsun2.harvard.edu Objet : Re: st: Calendar weeks 0. I hadn't noticed -epiweek- (SSC) -- please remember to explain _where_ user-written programs you refer to come from -- but you could just change the code in a cloned version. 1. See for a general review Nicholas J. Cox Stata tip 68: Week assumptions The Stata Journal Volume 10 Number 4: pp. 682-685 2. Suppose you have daily dates and a year variable then week numbering within a year for weeks starting on Mondays is given by bysort year (dailydate) : gen weekno = sum(dow(dailydate) == 1) With this rule any days before the first Monday in a given year are labelled 0. If you want week numbering always to start at 1 the fix will be something like replace weekno = weekno + 1 if dow(mdy(1,1,year)) != 1 3. You don't say what you expect to happen for weeks that begin in one calendar year and finish in the next. The start of the week for the current day is just gen monday = dailydate - cond(dow(dailydate) == 0, 6, dow(dailydate) - 1) In many ways the simplest system is to label weeks by the Mondays that start them; that cuts out the overlap issue. Nick On Wed, Feb 15, 2012 at 9:04 AM, Charles Vellutini <charles.vellutini@ecopa.com> wrote: > Sorry if this has been asked before (could not find it though): is there a function to compute the calendar week number (that is: the week starting on Monday and ending on Sunday) for any given date, or alternatively to compute the Monday of the week that date belongs to -- as opposed to the standard Stata approach to weeks (where the first week of the year is made of the first 7 days of the years, regardless of the day of the week of the first day of the year, and so on, if I am not mistaken). > > I am aware of user-written -epiweek- but that defines a week as starting on Sunday and ending on Saturday, so that won't work for me. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**RE: st: Calendar weeks***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: Calendar weeks***From:*Charles Vellutini <charles.vellutini@ecopa.com>

**Re: st: Calendar weeks***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: RE: By with forvalues** - Next by Date:
**Re: st: Execution of code out of the Stata Do-File-Editor: File not found** - Previous by thread:
**Re: st: Calendar weeks** - Next by thread:
**RE: st: Calendar weeks** - Index(es):