Announcement

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

  • Problem with date format

    I split a variable which had date and time together to one with just the dates.
    Now I am trying to convert it to a date numerical variable but its generating missing variables. I have used the same code for other dates and it worked just fine. Please let me know what is the error here.
    The code that I used was:

    gen long result_time = date(specimen_dt, "MDY" )

    Thanks

  • #2
    Your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared.

    If the code works on other data but not on the data you have now, then there is something different about the data. You can see your data, we cannot.

    Please help us help you. Show example data. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output.

    Comment


    • #3
      specimen_dt_tm
      6/11/13 2:32 PM
      6/12/13 5:39 AM

      This is the original variable and I split this and it made it into only a date variable. That's the only thing that is different with this and other dates.
      Please help me out.

      Comment


      • #4
        Actually, in your previous topic at

        https://www.statalist.org/forums/for...arranging-data

        your dates included 4-digit years such as "2013" while your example includes only 2-digit years such as "13". Details are important! Stata doesn't know what century the dates are in - you will need to tell it.
        Code:
        . gen long result_time = date(specimen_dt, "MD20Y")
        
        . format %td result_time
        
        . list, abbreviate(16) noobs
        
          +---------------------------+
          | specimen_dt   result_time |
          |---------------------------|
          |     6/11/13     11jun2013 |
          |     6/12/13     12jun2013 |
          +---------------------------+
        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


        • #5
          Thank you it worked!!!!!

          Comment

          Working...
          X