Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: Calendar weeks


From   Charles Vellutini <[email protected]>
To   "[email protected]" <[email protected]>
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 : [email protected] [mailto:[email protected]] De la part de Charles Vellutini
Envoyé : mercredi 15 février 2012 10:05
À : [email protected]
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. 

Thanks in advance,
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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index