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: Converting date/time string to proper date/time variable


From   Zachary Neal <[email protected]>
To   [email protected]
Subject   st: Converting date/time string to proper date/time variable
Date   Fri, 30 Aug 2013 10:58:19 -0400

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/


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