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


From   annoporci <[email protected]>
To   [email protected]
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

http://blog.stata.com/2012/04/02/the-penultimate-guide-to-precision/

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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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