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]

st: rounding error


From   Richard Fox <r.p.fox@bham.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: rounding error
Date   Tue, 20 Dec 2011 13:57:03 +0000

Dear statalist, 
I have written a program that summarises a continuous variable by a categorical variable and over a discrete time period, say Weight at a series of GP visits.

The results are generally as expected but sometimes the rounding does not seem to work. 

I capture the information I need as in the following example (this is just a small extract from the program, obviously there are argument definitions and tabulations etc.);

local acc = .1
qui su `x' if New`v' == Tnam[`i',1] & New`w'==Wnam`i'[`j',1],d
local Median_`i'_`j' = round(r(p50),`acc')

The results I obtain (see 2 examples below) often have values that have many decimal places which appears to suggest that the rounding is not working. However if I run a basic summary of the particular variable the results I get do not have the numerous decimal places so I'm not sure if the issue is with the rounding statement. Any ideas?


local acc = .1

. su Weight if Trt==1 & Week==3, d
My program in this case returns a value of 84.30000000000001 

                           Weight
-------------------------------------------------------------
      Percentiles      Smallest
 1%         75.6           75.6
 5%         75.6           93.1
10%         75.6              .       Obs                   2
25%         75.6              .       Sum of Wgt.           2

50%        84.35                      Mean              84.35
                        Largest       Std. Dev.      12.37437
75%         93.1              .
90%         93.1              .       Variance        153.125
95%         93.1           75.6       Skewness              0
99%         93.1           93.1       Kurtosis              1

. local x= r(p50)

. di `x'
84.35

. local y= round(r(p50),`acc')

. di `y'
84.3

. 
. 
. su Weight if Trt==2 & Week==1, d
My program in this case returns a value of  79.80000000000001
                           Weight
-------------------------------------------------------------
      Percentiles      Smallest
 1%         67.7           67.7
 5%         67.7           67.9
10%         67.7           73.3       Obs                   8
25%         70.6           78.5       Sum of Wgt.           8

50%        79.75                      Mean              85.15
                        Largest       Std. Dev.      16.55346
75%        103.1             81
90%        106.6          100.9       Variance       274.0171
95%        106.6          105.3       Skewness       .3192319
99%        106.6          106.6       Kurtosis       1.394482

. local x= r(p50)

. di `x'
79.75

. local y= round(r(p50),`acc')

. di `y'
79.8


Best Regards

Richard Fox


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