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]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

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

Subject |
st: RE: Stata date format %tw: how long is the weekend in a 9-day week? |

Date |
Fri, 29 Jul 2011 17:00:20 +0100 |

Please see SJ-10-4 dm0052 . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q4/10 SJ 10(4):682--685 (no commands) tip on Stata's solution for weeks and on how to set up your own alternatives given different definitions of the week For Stata, week 1 of any year starts on 1 January, regardless of what day it is. Week 52 may have (indeed will have) more than 7 days. These are unlikely to fit with many needs, and the Tip above is, in the absence of any apparent competition, all that is written on the subject. I agree, however, with your implication that this should all be better documented in the manual. The Stata 12 manuals do reference the Tip above. If we go back to basics, the facts are that weeks do not nest inside years or months and that practical definitions of week differ a lot, so Stata is agnostic on the point. Nick n.j.cox@durham.ac.uk -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Sergiy Radyakin Sent: 29 July 2011 16:50 To: statalist@hsphsun2.harvard.edu Subject: st: Stata date format %tw: how long is the weekend in a 9-day week? Dear All, I have a question regarding the Stata's %tw format. The manual (help dates_and_times) says in this format the numeric values are interpreted as: "a %tw value records the number of weeks from the first week of 1960" I have the following questions: 1) The year 1960 started on a Friday. Why is Wednesday the 6th of Jan 1960 is still considered the first week of 1960? See the following code, which shows the day-to-week assignment in the month of January 1960: forval i=0/30 { display wofd(`i') } Reformulating the question is the week reported in the format like 1975w9 A) the calendar week? B) the number of the 7-day-long group since the beginning of the year where a particular date belongs to? C) something else? 2) The second question comes as we depart from 1960 and move on to the current dates. For an example take a value like 1975. The date that is 1975 weeks away from the Jan 1, 1960 falls somewhere in early November 1997, while Stata reports it as the 52 week of the said year. I can substantiate the question with the example in Excel: Format a cell with the default date format. Enter the value 21916, which corresponds to Jan 1, 1960 (in the US notation 1/1/1960) Format another cell with the default date format. Enter a formula =A1+7*1975 - which will add 1975 weeks (of 7 days each) to the first date. The result (in the US notation) should be 11/7/1997. 3) My final question is related to the length of the year in weeks assumed by Stata: I have never seen Stata reporting the value YYYYw53 in any of the years, which is rather strange, since any year will contain dates beyond the 52 week. The investigation with the following code led to very interesting results: forval i=0/365 { display `i' " " wofd(`i') } Here 0-365 are the 366 days of the good old year 1960 which was a leap year. Interestingly, according to Stata the year ended in a long week consisting of 9 days!!! 357 51 358 51 359 51 360 51 361 51 362 51 363 51 364 51 365 51 (I just hope there was a very-long weekend :) Jan 1, 1961 (day 366) is then assigned week 52 and it lasts for 7 days as usual. The manual declares the valid range for week number 1-52, which agrees with the results above, but doesn't give any insight into the fact which week of the year will have 8 or 9 days. I don't think there is a bug in Stata with regards to the handling of dates (though the last issue illustrates an apparent unorthodox approach), but rather I seek a more elaborate explanation of how Stata comes to the (formatted) values like "1997w52" for value 1975 and the format %tw. The manual for date-time handling is rather cumbersome and is more elaborate about atomic time and leap seconds rather then 9-day weeks! Perhaps it can be improved by an easy "getting started" page that would deal with only one (recommended) format for date and the rest is put into a different reference-style topic. The version of Stata does not play a role here and the quoted results are reproducible in Stata v9-11 (Windows). Thank you, Sergiy Radyakin * * 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: RE: Stata date format %tw: how long is the weekend in a 9-day week?***From:*Sergiy Radyakin <serjradyakin@gmail.com>

**References**:**st: Stata date format %tw: how long is the weekend in a 9-day week?***From:*Sergiy Radyakin <serjradyakin@gmail.com>

- Prev by Date:
**RE: st: Stacked histogram - empty bins** - Next by Date:
**RE: st: Stacked histogram - empty bins** - Previous by thread:
**st: Stata date format %tw: how long is the weekend in a 9-day week?** - Next by thread:
**Re: st: RE: Stata date format %tw: how long is the weekend in a 9-day week?** - Index(es):