Announcement

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

  • Change Date to Numeric Issue

    Hi all,

    I'm trying to change the values of my string date variable to numeric date variable. Currently the format is like this:

    12/03/23
    12/01/23
    11/30/23
    11/28/23

    I tried to use numdate to convert the values after removing the "/" using subinstr but (I think?) since the year value is 23 and not 2023, the numdate command isn't working.

    Is there a way to convert the dates to numerics using numdate whilst only having the "23" for year or how can I add "20" in front of the "23"s for all values and use numdate after that?

  • #2
    numdate from SSC will work perfectly well so long as you tell it about the century. In this respect it's no different from Stata's date-time funcions. Examples are included in the help.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str8 date
    "12/03/23"
    "12/01/23"
    "11/30/23"
    "11/28/23"
    end
    
    numdate daily wanted = date, pattern(MD20Y)
    
    list 
    
         +----------------------+
         |     date      wanted |
         |----------------------|
      1. | 12/03/23   03dec2023 |
      2. | 12/01/23   01dec2023 |
      3. | 11/30/23   30nov2023 |
      4. | 11/28/23   28nov2023 |
         +----------------------+

    Comment


    • #3
      Thank you! Worked perfectly

      Comment

      Working...
      X