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]
Re: st: date/time question
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: date/time question
Date
Thu, 10 Feb 2011 10:40:54 +0000
On the last
"26/12/2008 09:51:17:210"
is problematic but
"26/12/2008 09:51:17.210"
isn't. So whenever you have three colons the last must be changed to a
stop or period.
A test for three colons is
if (length(mydate) - length(subinstr(mydate, ":", "",.))) == 3
and you can change it by
reverse(subinstr(reverse(mydate), ":", ".", 1))
Code not tested.
On Thu, Feb 10, 2011 at 10:27 AM, Dimitri Szerman <[email protected]> wrote:
> 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?
*
* 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/