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 |
Sergiy Radyakin <serjradyakin@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Fri, 29 Jul 2011 11:49:56 -0400 |

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/

**Follow-Ups**:**st: RE: Stata date format %tw: how long is the weekend in a 9-day week?***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: Question about modified park test** - Next by Date:
**Re: st: RE: Memory usage in Stata 11 and 12** - Previous by thread:
**st: imtest for panel data runs** - Next by thread:
**st: RE: Stata date format %tw: how long is the weekend in a 9-day week?** - Index(es):