Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • ISOweek from dates in Stata: Code below

    There is no direct command for generating the ISOweek (ISO8601) from a date in Stata.
    The following single-line formula derives the ISOweek from any date post 1 Jan 1900.
    Should you require ISOweeks from _before_ that date, substitute mdy(1,1,1753) for mdy(1,1,1900), and that will get you back to before the Industrial Revolution!

    ** derived from the EXCELLENT description of
    ** how to derive an ISOweek from a date
    ** described here: https://www.sqlservercentral.com/art...so-week-number
    ** based on a post here: http://stackoverflow.com/questions/7...ql-server-2005
    ** from "t-clausen.dk"


    gen ISOweek =int((doy(7*int((datevariable-mdy(1,1,1900))/7)+ mdy(1,1,1900) + 3)+6)/7)

  • #2
    Helpful resource. I suspect that people want this often enough that it should be an official function (and I mean function, not command...).

    Comment


    • #3
      Yes; it is so easy to implement, no reason why it should not be added to the standard suite of date functions.
      (and while at it, to implement the CDC/MMWR week - available via the epiweek ssc - and the ONS/PHE week, definitions too)

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Helpful resource. I suspect that people want this often enough that it should be an official function (and I mean function, not command...).
        Hi Nick!

        Any updates on making this an official function?

        / Simon

        Comment


        • #5
          It remains a personal view that an official function would be widely appreciated.

          Comment

          Working...
          X