Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Calculating what week of the year a day is


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Calculating what week of the year a day is
Date   Mon, 15 Apr 2013 10:56:24 +0100

That depends on your definition of week. Stata has its own definition
whereby week 1 always begins on 1 January and week 52 is always 8 or 9
days long.

Thus we are now in week 15 as is shown by

. di week(mdy(4,15,2013))
15

and some experiment shows that it ends today and week 16 starts tomorrow.

. di week(mdy(4,8,2013))
14

. di week(mdy(4,16,2013))
16

If you don't like that definition, then you need to say what your
definition is and write a few lines of code accordingly.

I doubt there is a day of the week that isn't special to some country
or culture or religion.

Also, users find this definition strange -- even down to the incorrect
assertion that the -week()- function is broken -- but it is the just
about the only definition that ensures that weeks are nested within
years.

The easiest convention otherwise is to define weeks by the days that
start them using the -dow()- function. The easiest example is Sunday,
from which a week identifier from daily data is just

gen myday = mdy(month, day, year)
gen mysunday = myday - dow(myday)

Then you can aggregate to weeks using the new identifier.

A search for "week" in the list archives brings up answers in similar spirit.

See also for much more detail -- including the messy cases of
splitting weeks into months --

Cox, N.J. 2010. Stata tip 68: Week assumptions. Stata Journal 10(4): 682--685

Cox, N.J. 2012. Stata tip 111: More on working with weeks.
Stata Journal 12(3):  565--569 [Erratum 12(4): 765]











Nick
njcoxstata@gmail.com


On 15 April 2013 05:29, Md. Alauddin Majumder <mm4v@mtmail.mtsu.edu> wrote:
> Dear Statalist,
> I have day, month and year data. Just wondering how to calculate what week of the year a day is. Any help will be greatly appreciated.
>
> Regards
> Majumder
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index