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: RE: round


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: round
Date   Wed, 14 Sep 2011 11:54:15 +0100

I recommend otherwise.

Confusing (1) what decimal number you want stored, (2) how that is
held in binary and (3) what is to be displayed, which is really a
string, is a recipe for frustration.

To get a display to so many decimal places, use the appropriate
-format-. -round(whatever, .01)- just replaces one binary
approximation by another. Most multiples of .01 cannot be held
exactly.

-round()- is a very useful function for rounding to (multiples of)
integers. It is also defined, evidently, for non-integer second
arguments, but that does not mean it can deliver the impossible.

Over the years on Statalist, this question has I guess wildly appeared
hundreds of times. -search precision- for blog entries, articles and
FAQs on the subject, starting with anything written by Bill Gould.

Nick


On Wed, Sep 14, 2011 at 11:37 AM, Tim Evans <Tim.Evans@wmciu.nhs.uk> wrote:
> Would the following do the trick for you?
>
> gen real=round(obs, .01)
>
> Substitute real with the name of what you want to call your variable and replace obs with the name of the variable containing the .4378
>
> Tim
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Carla Horlacher
> Sent: 14 September 2011 11:24
> To: statalist@hsphsun2.harvard.edu
> Subject: st: round
>
> Hallo all!
>
> I have a quick question:
>
> how do I round numbers like .4378 to get only 2 digits after the point?
>
*
*   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