Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: date-time conversion problems [was: RE: RE: statalist-digest V4 #4311]

From   Nick Cox <>
To   "''" <>
Subject   st: date-time conversion problems [was: RE: RE: statalist-digest V4 #4311]
Date   Fri, 21 Oct 2011 15:24:00 +0100

. help dates and times 

bears this warning: 

		                  DO NOT FORGET                                 |
                  %tc and %tC values MUST BE stored as doubles. 
                  Doing so is your responsibility, not Stata's. 

See for a reminder from just last Monday:

So, try that first. 

gen double time2 = ... 


Mark McCann

                I'm at a loss as to what's happening here. I have checked the help files and statalist, but I just can't make sense of this. My time variable appears to be reading seconds incorrectly, this happened before I added a dummy ":00" seconds onto the string variable, and after (as below). Any ideas on what is happening? I'm using Stata 11 on Windows

gen space=" "
gen seconds=":00"
egen time1=concat(date space time seconds)
gen time2=clock(time1,"DMYhms")
format time2 %tc

Here are the results for the first observation, I've fixed these to stop formatting problems

Date 01/05/2011   
Time 00:01       
Seconds :00   
Time1 [The used variable] 01/05/2011 00:01:00   

Time2 [The final variable] 01may2011 00:00:28 

Similar errors occur throughout, in some cases rounding up or down would give the wrong result so I can't use a quick fix and ignore the problem!

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index