Announcement

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

  • Change in date format

    Hi All,
    I need to change the format of birthdate from 01feb1951 13:00:00 to YYYY-MM-DD. Any help would be appreciated.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float id double birth_date
     1 -2.812716e+11
     2 -3.422952e+11
     3 -1.701036e+11
     4  -4.37508e+11
     5 -4.077864e+11
     6 -1.265544e+11
     7 -3.129192e+11
     8 -4.947084e+11
     9  -3.10068e+11
    10   8.63316e+10
    end
    format %tc birth_date

    Thank you
    Last edited by gani davlatyov; 11 Mar 2020, 12:12.

  • #2

    Code:
     format birth_date %tdCY-N-D
    Best regards,

    Marcos

    Comment


    • #3
      Code:
      %tcCY-N-D

      Comment


      • #4
        For the full details on how the magic in posts #2 and #3 works, you have to follow the link in the output of help datetime to the description of datetime display formats, or else go there directly with
        Code:
        help datetime display formats

        Comment


        • #5
          My interpretation was that you wish to get rid of the clock, hence "td" in the command line. Nick (as always) must have guessed correctly, I mean, maybe you wish to keep the clock, and for this you should use "tc" instead. That said, the message in #1 raised doubts about this particular aspect.
          Best regards,

          Marcos

          Comment


          • #6
            Changing the display format doesn't do anything else. Gani has values like 10^11 which is fine as ms since the start of 1960, but not as days since the start of 1960.

            More at https://journals.sagepub.com/doi/pdf...867X1201200415

            Comment


            • #7
              Nick's point is well made. The data are date and hour; if by "change the format" Gani did not mean "change the formatting used to display the data" but rather "change the data to no longer include the hour" then Nick's reference points the way with an example changing daily data to monthly data.

              And the underlying lesson for gani davlatyov is that Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

              All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

              Comment

              Working...
              X