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: problem using -clock- with military time
From
Steve Nakoneshny <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: problem using -clock- with military time
Date
Fri, 1 Jun 2012 16:39:33 -0600
Statalisters,
I have been provided with a dataset containing date and time variables in string format. I wish to convert these to SIF type using the -clock- function, however I have run into a small problem given that the times are formatted as military time (sadly without the leading zero). The code -gen double pcutime = clock(ArrivedOnPCU, "YMDhm")- executes imperfectly.
After formatting pcutime to %tc, I can see that some of the times translate imperfectly:
ArrivedOnPCU pcutime
2011/04/06 1630 06apr2011 16:30:00
2010/07/18 700 .
2011/09/06 400 .
2011/06/23 130 23jun2011 13:00:00
If I manually edit the second obs to read as "2010/07/18 0700" and -replace pcutime = clock(ArrivedOnPCU, "YMDhm"), pcutime displays 18jul2010 07:00:00. It is pretty obvious to me that I'm choosing the wrong mask in the clock function to fail to account for both the missing values in pcutime as well as the incorrect times (i.e. 0130 translating to 13:00).
I've tried a various permutations of hm/HM/HHMM/hhmm to try to adjust, but to no avail. Can anybody suggest a better mask for me to use? Or perhaps some relatively simple means of inserting a leading "0" into the time portion of the string prior to using -clock-?
Thanks,
Steve
*
* 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/