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: Converting date/time string to proper date/time variable
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Converting date/time string to proper date/time variable
Date
Fri, 30 Aug 2013 15:07:30 +0000
. gen double date_obs = clock(datetime_obs, "MD20Yhm")
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Zachary Neal
Sent: Friday, August 30, 2013 10:58 AM
To: [email protected]
Subject: st: Converting date/time string to proper date/time variable
I am attempting to convert a date/time variable imported as a string
(original) into a proper time variable (converted) using the following
syntax:
gen date_obs = clock(datetime_obs, "MD20Yhm") format date_obs %tc
This is what I get:
original converted
4/4/12 10:34 AM 04apr2012 10:34:10
4/4/12 10:48 AM 04apr2012 10:47:17
4/5/12 10:40 AM 05apr2012 10:40:20
4/5/12 10:54 AM 05apr2012 10:53:26
4/10/12 10:25 AM 10apr2012 10:25:16
4/11/12 10:13 AM 11apr2012 10:13:57
4/11/12 10:48 AM 11apr2012 10:48:54
4/16/12 9:29 AM 16apr2012 09:28:18
4/16/12 9:51 AM 16apr2012 09:50:08
4/16/12 10:22 AM 16apr2012 10:22:54
As you can see, this mostly works, but seems to be randomly adding or subtracting seconds from the times. I'd like the "converted" variable to either not include seconds at all, or at least indicate 00 seconds in every case. I'd appreciate any thoughts on what might be causing this and how to fix it.
Thanks,
Zachary
--
Zachary Neal, PhD
Department of Sociology
Michigan State University
[email protected]
http://www.msu.edu/~zpneal
*
* 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/