Announcement

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

  • datetime

    Dear All, Suppose I have the following data
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float timeid str10 time double time1
     1 "2010.06.17" -1.8934272e+12
     2 "2010.06.18" -1.8934272e+12
     3 "2010.06.20" -1.8934272e+12
     4 "2010.06.21" -1.8934272e+12
     5 "2010.06.22" -1.8934272e+12
     6 "2010.06.23" -1.8934272e+12
     7 "2010.06.24" -1.8934272e+12
     8 "2010.06.25" -1.8934272e+12
     9 "2010.06.27" -1.8934272e+12
    10 "2010.06.28" -1.8934272e+12
    end
    format %tchh:MM time1
    How can I combine `time' and `time1' into a standard Stata datetime/c format (say, "2010.06.17 08:00:00")?
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    Why is time1 negative? In the example you've given it is constant and negative: is this always true? I find

    Code:
    . di %tc -1.8934272e+12
    31dec1899 08:00:00
    How are we supposed to think about that?

    Comment


    • #3
      Like Nick, I am curious how your times came to be expressed as relative to the last day of 1899. But given that they are,
      Code:
      generate double dt = dhms(date(time,"YMD"),hh(time1),mm(time1),ss(time1))
      format dt %tc
      will generate a Stata Internal Format datetime value, and assign the default format to it. For a format more to your liking, help datetime display formats will give you plenty of guidance.

      Comment


      • #4
        Hi, Nick: The question was taken from the Chinese Stata forum. I simply re-post the question and seek for answer. At this point, I am unable to reply why `time1' is negative (but is is the raw data from someone).

        Ho-Chuan (River) Huang
        Stata 17.0, MP(4)

        Comment


        • #5
          Hi, William: As I replied to Nick, the question/data is from someone else. But your suggestion seems to be the answer to the question. Thanks a lot.

          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment

          Working...
          X