Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: help on round function


From   Fred Wolfe <[email protected]>
To   [email protected]
Subject   RE: st: help on round function
Date   Sat, 10 Dec 2005 15:36:46 -0600

There is a Stata FAQ on precision: float versus double.

. gen y =7.995

. gen y2 =round(y,.01)

. di y2
7.9899998

. gen double y3 =round(y,.01)

. di y3
7.99

. gen double x=7.995

. gen double x3 =round(x,.01)

. di x3
8

The answer (in part) is that it depends on how your X variable is stored, either as a float or a double. Find the FAQ for further insight.


Fred


At 03:24 PM 12/10/2005, you wrote:

Fred,
I got that. But if I have a variable
X
8.575
7.995
10.324
and I do: gen y =round(x,.01), I get
Y       not  Y
8.57    8.58
7.99    8.00
10.32   10.32

what I need. What am I doing wrong?

Thanks,
Pinaki Mitra
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Fred Wolfe
Sent: Saturday, December 10, 2005 3:44 PM
To: [email protected]
Subject: Re: st: help on round function

At 01:26 PM 12/10/2005, you wrote:
>Hello List,
>
>How do I use the round function to round off 8.755 to 8.76, 8.754 to
>8.75?


. di round(8.755,.01)
8.76
[MITRA PINAKI ] 8
. di round(8.754 ,.01)
8.75

Fred Wolfe

>Thanks,
>Pinaki Mitra
>
>*
>*   For searches and help try:
>*   http://www.stata.com/support/faqs/res/findit.html
>*   http://www.stata.com/support/statalist/faq
>*   http://www.ats.ucla.edu/stat/stata/


Fred Wolfe
National Data Bank for Rheumatic Diseases
Wichita, Kansas
Tel (316) 263-2125     Fax (316) 263-0761
[email protected]


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

Fred Wolfe
National Data Bank for Rheumatic Diseases
Wichita, Kansas
Tel (316) 263-2125     Fax (316) 263-0761
[email protected]


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index