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: RE: Question on converting time-variable
From
"Barclay Matthew (PUBLIC HEALTH ENGLAND)" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Question on converting time-variable
Date
Tue, 1 Oct 2013 10:32:18 +0100
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)?
Thanks in advance,
Simon
*
* 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/
********************************************************************************************************************
This message may contain confidential information. If you are not the intended recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take any action in reliance on its contents:
to do so is strictly prohibited and may be unlawful.
Thank you for your co-operation.
NHSmail is the secure email and directory service available for all NHS staff in England and Scotland
NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and GSi recipients
NHSmail provides an email address for your career in the NHS and can be accessed anywhere
********************************************************************************************************************
*
* 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/