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: rounding the minimum of a negative number

From   annoporci <>
Subject   Re: st: rounding the minimum of a negative number
Date   Thu, 10 Jan 2013 08:59:27 +0800

The best starting point is now William Gould's blog entry

Thanks a lot for the reference Nick, I'll look it up.

1. At machine level Stata's calculations are necessarily in binary.
Stata and most modern software go to enormous lengths to make it seem
otherwise, but the fact is inescapable, ineluctable and inevitable.

Sure, I can't argue with that, but I would have expected Stata to keep a few digits of zeros stored in memory (say 6 zeros), instead of making up its own digits.

Somewhere in StataCorp's files a suggestion of mine that a second argumentbe allowed for these functions

That would be a great addition!

The best you can do, I believe, is indeed something like

gen double myresult = floor(100 * mydata) / 100

Got it, thanks Nick.

You mention r(min) in your example; presumably that arises from some
previous calculation. It is not a general solution.

Sorry, I was imprecise, the r(min) comes after -sum-, at the end of the code given at the bottom of my message.

P.S. Your last example brings in a different point. `r(min)' is
related to r(min) as local macros are to scalars. Macros hold less
precision than scalars. For maximum precision, avoid the numeric --
string -- numeric cycling required by putting a numeric result into a
local macro and then taking it out again. (This won't bite with small
or moderate integers.)

I see, I hadn't noticed that macros hold less precision than scalars.

Great tips, thanks a lot for your help Nick.

Patrick Toche.
*   For searches and help try:

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