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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: precision problem using double


From   Stas Kolenikov <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: precision problem using double
Date   Sun, 16 Oct 2011 14:29:09 -0500

On top of NJC's response (which is on the spot, of course, as always),
another useful function is -reldif- along with -epsfloat-/-espdouble-
(which gives the relative accuracy, unlike the -smallestdouble- that
gives a number that is way too small to be relevant):

sysuse auto
sum gear_ratio
list if gear_ratio == 3.89
list if reldif(gear_ratio, 3.89) < 10*c(epsfloat)

This comes handy in comparisons with fixed known constants. Of course,
in your case, you should use -r(max)- which is a scalar with double
precision (2e-16) rather than -`r(max)'- which is a string; if the
latter is in scientific notation, it may have accuracy lower than
1e-15.

On Sat, Oct 15, 2011 at 1:37 AM, Leandro Brufman
<leandrobrufman@gmail.com> wrote:
> Been reading some stuff on the precision of double, and how Stata
> reads numbers for calculation (in particular this article
> http://www.stata-journal.com/sjpdf.html?articlenum=dm0022)
> But couldn't find a solution. Here's my problem:
>
> sum  spread
> br if spread==`r(max)'
>
> * it returns that there are no observations.
>
> sum spread
> br if spread-`r(max)'<smallestdouble()
>
> *it also returns that there are no observations
>
> sum  spread
> gen test=spread-`r(max)'
>
> * the minimum number of variable test is -2.84217094e-14
>
> any ideas on how to fix this code? i don't need a lot of precision,
> but I do need to have these two lines working fine:
> sum  spread
> br if spread==`r(max)'
>
>
> as usual, many many thanks in advance...
> *
> *   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/
>



-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index