Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

RE: st: best practice for dates and times

From   Nick Cox <>
To   "''" <>
Subject   RE: st: best practice for dates and times
Date   Mon, 21 Feb 2011 17:22:32 +0000

I note these evident inconsistencies as questions for StataCorp. 

Otherwise, we need to be clear here about the difference between functions such as -clock()- and commands such as -generate-. 

I don't think this request matches the way functions work. They just take inputs (in most cases) and produce outputs. I don't think that there is any sense in which they know about any wider context, as for example being part of a -generate- or -replace- command. Part of the magic of computing follows from very strong division of labour like this. 

I think what you and Junlin are asking is that -generate- (and -replace-) be smarter when the expression they are fed contains a call to e.g. -clock()-. That's a different request. My only bet is that this is much trickier than it seems, in principle as well as in practice. For example, even if -clock()- is part of the expression, it doesn't always follow that the user wants a -double- variable as a result. The spirit of the request is understandable, but I think there is a slippery slope ahead. 


Joseph Coveney

I'm inclined to agree with Junlin on this.  The user has to supply a mask for 
the date-time data as the second argument.  It seems to me that the function 
should be able to determine from that information whether double-precision is 
needed, whether single-precision will be adequate, and even when integer will 

Stata is not entirely consistent in automatically detecting and setting the 
proper storage type.  For example, back on the earlier thread, typing 
-generate y = 83085733- won't set the data type to the necessary precision, but
opening the data editor and pasting 83085733 into the first cell and closing 
*does* set the data type to long.  

And, typing -generate float y = 1- and then -replace y = 83085733- won't 
automatically promote the data type to accommodate the larger value.  On the
other hand, first entering -generate byte y = 1- and then -replace y = 83085733-


Junlin Liao wrote:

. . . I thought -clock- or -Clock- would be smart enough to figure it out by 
itself.   . . . I think there again is a chance for Stata to get smart.

*   For searches and help try:

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