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]

RE: st: best practice for dates and times


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: best practice for dates and times
Date   Mon, 21 Feb 2011 20:11:17 +0000

I am afraid that for me your verbalisation of what you think is happening casts no light on the most recent specific examples. I am wary of claiming "proof" of internal operation when all I see are inputs and outputs. 

Nick 
[email protected] 

Liao, Junlin

Nick,

What you observed is explained by another mechanism and this mechanism further proves that -replace- takes consideration of inputs. -replace- will use double if a variable with double type is involved in calculation, and it will use float if float variable is involved. It goes float if both double and float are involved. It goes to double again if float cancels each other out. Same is true with double. It does not make sense to go float when both double and float are involved (it does not matter if you set type to double).

Junlin


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, February 21, 2011 1:17 PM
To: '[email protected]'
Subject: RE: st: best practice for dates and times

Good question. There appears to be some switch in the code and I don't know what it is.

As said, I'd be surprised if the switch was -replace- detecting the use of -clock()- but I might well be wrong.

Here is another experiment. If you also go

gen byte x2 = 1
replace x2 = x

-x2- is also replaced as double. In what sense does the second -replace- also know that its argument came from a -clock()- calculation, as you seem to be supposing? I doubt that it does, but any amount of guesswork can only be settled by looking at the source code.

Nick
[email protected]

Liao, Junlin

Maarten,

How do you explain the following? I found out that it does not matter if you set type to float or double. -replace- always promote decimal numbers to float for most of calculations. However, for -clock()- results, it chooses double. If you and Nick are correct, then the results should be consistently of one type or the type according to setting.


. clear

. set type float

. set obs 1
obs was 0, now 1

. gen byte x=1

. replace x=clock("1may2001 1:20","DMY hm") x was byte now double
(1 real change made)

. gen byte y=1

. replace y=2.123456^3
y was byte now float
(1 real change made)

. des

Contains data
  obs:             1
 vars:             2
 size:            16 (99.9% of memory free)
--------------------------------------------------------------------------------------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
--------------------------------------------------------------------------------------------------------------------------------------------------------------
x               double %8.0g
y               float  %8.0g
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by:
     Note:  dataset has changed since last saved

Junlin


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Maarten buis
Sent: Monday, February 21, 2011 12:45 PM
To: [email protected]
Subject: RE: st: best practice for dates and times

---  Liao, Junlin
> Please note in previous code I had intentionally set type to float.
> -replace- still choose double for results of -clock-. Suppose I do
> another calculation, -replace- will choose float. Therefore, -replace-
> must know about -clock-.

--- On Mon, 21/2/11, Nick Cox wrote:
> As I understand it, -replace- looks at values, not what produced them.
> If it sees a particular number that should be stored as -double-, it
> is not because it comes tagged with a history "produced by -clock()-;
> act accordingly".

Nick seems to be right, -replace- will increase the storage type regarless of what function produced it, just not float, which I think is a sensible default given what was said before.

set obs 1
gen byte foo = 1
replace foo = 10000
desc


*
*   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/


________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________

*
*   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/

*
*   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/


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