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.

# st: RE: Calendar weeks

 From Charles Vellutini To "statalist@hsphsun2.harvard.edu" Subject st: RE: Calendar weeks Date Wed, 15 Feb 2012 01:26:04 -0800

```Dear Statlisters,

Follow-up: I am sure there are more elegant solutions, but this seems to work ("lundi_sem" is the Monday of the week "date"  belongs to):

gen lundi_sem=.
format lundi_sem %td

local N = _N
forvalues i = 1/`N' { //cette boucle copie date du lundi semaine sur chaque jour de la semaine concernée
if dow[`i'] == 1 {
qui replace lundi_sem = date in `i'
}
else if dow[`i'] == 0 {
qui replace lundi_sem = date - 6 in `i'
}
else {
qui replace lundi_sem = date - dow +1 in `i'
}
}

Charles

-----Message d'origine-----
De : owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] De la part de Charles Vellutini
Envoyé : mercredi 15 février 2012 10:05
À : statalist@hsphsun2.harvard.edu
Objet : st: Calendar weeks

Dear Statlisters,

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.

Charles

*
*   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/
```