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: RE: Question on converting time-variable
From
Simon Falck <[email protected]>
To
[email protected]
Subject
Re: st: RE: Question on converting time-variable
Date
Tue, 01 Oct 2013 23:28:24 +0200
Nick,
As usual, you make a very good point. Yes, I need to add milliseconds to
the time.
Thanks!
Best,
Simon
On 2013-10-01 16:52, Nick Cox wrote:
The assumption here is that 2400 should be 0000, but otherwise the day
is correct. If you think that the day should be the next day, you
would need add
24 * 60 * 60 * 1000
milliseconds to the time.
Nick
[email protected]
On 1 October 2013 10:32, Barclay Matthew (PUBLIC HEALTH ENGLAND)
<[email protected]> wrote:
Hi Simon,
One approach would be:
// string containing first half of start variable
gen pre_start = substr(start,1,11)
// string containing second half...
gen post_start = substr(start,-4,.)
// replace "2400" with "0000"
replace post_start = "0000" if post_start == "2400"
// recombine pre_ and post_start
egen new_start = concat(pre_start post_start)
// generate starttime etc
HTH,
Matt
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Simon Falck
Sent: 01 October 2013 09:55
To: [email protected]
Subject: st: Question on converting time-variable
Dear Statalist,
Working with Stata 11.2, I want to convert two string variables (start,
stop) with time information showing year-month-day-hour-minutes, e.g.
"1998 10 19 1000" to time-format so "01oct1998 10:00:00", which can
easily done by,
gen double starttime=clock(start, "YMDhm")
format starttime %tc
However, it appears that my timevariables (strings), i.e. the strings,
sometimes indicate midnight as 2400, e.g. "2004 12 13 2400" and sometime
as 0000, e.g. "1999 10 26 0000", and Stata seems only to accept the
latter, implying that observations that indicate midnight as "2400" are
not converted.
My question how to convert observations that indicate midnight as 2400
to 0000 in the string variable(s), or to time variable(s)?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/