Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: RE: rounding in STATA


From   "Siyam, Amani" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: RE: rounding in STATA
Date   Thu, 13 Apr 2006 15:50:47 +0200

sorry my mistake, 

the command line should read
gen y=round(x, 0.1)

y is what I got after that.

Thanks again.

Amani

 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 13 April 2006 15:47
To: [email protected]
Subject: st: RE: RE: RE: rounding in STATA

Another reason for not trusting your example
is that you claim to show us the results of

gen x = round(y, 0.1) 

but in your output it is y that is rounded
and x that is coarse. So, evidently you changed 
something before showing us your results. 

Nick 
[email protected] 

Siyam, Amani
 
> Thanks for your reply Maarten, the values of x are exact ones and that
> happens whenever you have "50" after the decimal you are cutting, for
> example 0.*50, for the one decimal place, 0.**50 for the two decimal
> place...etc.

Maarten Buis
 
> Stata 8.2 doesn't show this behaviour:
> 
> . input x 
> 
>              x
>   1. 8.750
>   2. 5.752
>   3. 23.256
>   4. end
> 
> . gen y = round(x, 0.1)
> 
> . list
> 
>      +---------------+
>      |      x      y |
>      |---------------|
>   1. |   8.75    8.8 |
>   2. |  5.752    5.8 |
>   3. | 23.256   23.3 |
>      +---------------+
> 
> 
> Maybe 8.750 in your data is actually 8.7499?

Siyam, Amani
 
> I have a minor issue with the way STATA is rounding, for example a
> variable to one decimal place.
> 
> I used the command
> 
> gen x=round(y, 0.1)
> 
> Comparing the two variables, I noticed the that when:
> 
>    x=                     y=
> 
>  8.750           8.7
>  5.752           5.8
> 23.256          23.3
> 
> Is there a way I can modify the function to round "x"=8.750 to be 8.8
> 
> Or should I put together my own code to get the rounding I want.

*
*   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/



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