Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: date/time question


From   Dimitri Szerman <[email protected]>
To   statalist <[email protected]>
Subject   st: date/time question
Date   Thu, 10 Feb 2011 10:27:49 +0000

Hello,

I have a string variable which contains information on dates and time.
It looks like this:

input str23 mytime
"24/12/2008 10:21"
"25/12/2008 09:01:27"
"25/12/2008 09:23:23"
"25/12/2008 09:36:03"
"26/12/2008 09:00:27:803"
"26/12/2008 09:31:43:163"
"26/12/2008 09:49:03:943"
"26/12/2008 09:49:35:913"
"26/12/2008 09:51:17:210"
end

I'm trying to convert this into a numeric variable. My ideas was

gen double numtime = clock(mytime, "DMY hms")
format numtime %tC

But that's giving me missing values. I guess my problem is, the
appropriate mask changes (for observation 1 it should be "DMY hm", for
observations 2-4, "DMY hms", and for observations 5-9, I have no
idea).

By the way, I'm importing many ASCII files in loop, so sometimes I
have only the  "DMY hm" format, sometimes only the "25/12/2008
09:01:27" format, and sometimes a mix of the three formats above.

Any ideas on how to solve this problem efficiently?

Many thanks,
Dimitri
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index