Announcement

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

  • Display Stata date serial number

    Hi all

    I need to sum up some statistics for all observations which have a date of december-2021 or later. The command would look something like:

    Sum var if date>=[stata serial number for 1/12/2021]

    My question is if there is an easy way of displaying serial numbers for dates in Stata?

    I know how to solve the problem doing:

    gen dec = date("1/12/2021", "MDY")
    tab dec

    But I wonder if there would be a less tedious way?
    Last edited by Emil Alnor; 06 Jan 2022, 08:58.

  • #2
    The terminology "serial number" is nonstandard. Stata dates are referred to as SIF (Stata Internal Form) values. There are convenience functions for these, e.g., -td()-

    Code:
    help td()
    Code:
    di td(06jan2022)
    assert  date("1/12/2021", "MDY") > td(10jan2022)
    Res.:

    Code:
    . di td(06jan2022)
    22651
    
    .
    . assert  date("1/12/2021", "MDY") > td(10jan2022)
    assertion is false
    r(9);
    
    .
    Last edited by Andrew Musau; 06 Jan 2022, 10:13.

    Comment


    • #3
      Thanks, Andrew!

      Comment

      Working...
      X