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: RE: Problem with caption in a graph


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: RE: Problem with caption in a graph
Date   Sun, 8 Sep 2013 00:04:32 +0100

Except that you wanted 3 d.p. so that the format should be more like %4.3f.

Nick
[email protected]


On 7 September 2013 23:21, Nick Cox <[email protected]> wrote:
> -round()- just changes one number to another; it's incorrect to use it
> for what is here string manipulation, i.e. formatting a decimal
> fraction for output. The associated problem is that most decimal
> fractions cannot be held as exact binary equivalents.  For further
> enlightenment see William Gould's blog posts on precision at
> blog.stata.com
>
> Avoid -round()- altogether here:
>
> reg y x
> local r2 : di %2.1f e(r2)
> line y x, caption("R2=`r2'" , size(small) position(2) ring(0))
>
> See also -aaplot- (SSC).
>
> Nick
> [email protected]
>
> On 7 September 2013 22:54, Joe Canner <[email protected]> wrote:
>
>> I've seen this problem before in a user-written module and I think the author solved it by converting the number to a string at the same time, something like this:
>>
>> local r2=string(round(e(r2),0.001),"%5.3f")
>>
>> I think it might even work to leave out the -round()- because formatting the number in string() should round automatically.  (Sorry, I can't check at the moment).
>
> Benjamin Villena [[email protected]]
>
>>  I want to place the R-squared of a regression on a graph using a code like this
>>
>> reg y x
>> local r2=round(e(r2),0.001)
>> line y x, caption("R2=`r2'" , size(small) position(2) ring(0))
>>
>> The problem is that the caption text shows R2=0.87600000000000000000001 despite the fact I'm using round to keep only three decimal digits.
>>
>> I'd appreciate if you can give me some advice on how to deal with this issue.
*
*   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