Hello,
I am experiencing rounding errors when using the format function. I am using a personnal dataset with red blood cell counts: an example of the values I have would be 1.284E+13 (cells/mL). I perform summary statistics using the tabstat function with the format option to display 3 decimals to the right of the decimal point. Here is the function call:
tabstat D1, statistics( mean sd var median ) by(Group) columns(statistics) longstub
And the result (two digits to the right of the decimal point):
Group variable | mean sd variance p50
----------------------+----------------------------------------
1 D1 | 1.26e+13 1.08e+12 1.16e+24 1.26e+13
2 D1 | 1.15e+13 2.64e+12 6.98e+24 1.20e+13
3 D1 | 1.21e+13 6.20e+11 3.84e+23 1.21e+13
4 D1 | 1.22e+13 6.56e+11 4.30e+23 1.21e+13
----------------------+----------------------------------------
Total D1 | 1.21e+13 1.48e+12 2.20e+24 1.22e+13
---------------------------------------------------------------
Now, because I wanted 3 decimals, I modified the command line to:
tabstat D1, statistics( mean sd var median ) by(Group) columns(statistics) longstub format(%10.3f)
And get the following results:
Group variable | mean sd variance p50
----------------------+----------------------------------------
1 D1 | 1.263e+13 1.079e+12 1.165e+24 1.260e+13
2 D1 | 1.146e+13 2.642e+12 6.983e+24 1.200e+13
3 D1 | 1.209e+13 6.198e+11 3.841e+23 1.210e+13
4 D1 | 1.221e+13 6.556e+11 4.298e+23 1.205e+13
----------------------+----------------------------------------
Total D1 | 1.210e+13 1.484e+12 2.203e+24 1.215e+13
---------------------------------------------------------------
Variance for group 1 is 1.165E+24, rounded to 1.16E+24 in the first table. It should be rounded to 1.17E+24. I've tried different format options but nothing changes. This happens on other statistics of the same kind when Stata rounds a number ending in 5. Is there a way to force Stata to round as it should be? I am using Stata 14 but had the same problem with Stata 13.1.
Has anybody had the same problem or does anybody know if this is merely because my command is not correct or if this is a bug?
Thank you,
Mathias
I am experiencing rounding errors when using the format function. I am using a personnal dataset with red blood cell counts: an example of the values I have would be 1.284E+13 (cells/mL). I perform summary statistics using the tabstat function with the format option to display 3 decimals to the right of the decimal point. Here is the function call:
tabstat D1, statistics( mean sd var median ) by(Group) columns(statistics) longstub
And the result (two digits to the right of the decimal point):
Group variable | mean sd variance p50
----------------------+----------------------------------------
1 D1 | 1.26e+13 1.08e+12 1.16e+24 1.26e+13
2 D1 | 1.15e+13 2.64e+12 6.98e+24 1.20e+13
3 D1 | 1.21e+13 6.20e+11 3.84e+23 1.21e+13
4 D1 | 1.22e+13 6.56e+11 4.30e+23 1.21e+13
----------------------+----------------------------------------
Total D1 | 1.21e+13 1.48e+12 2.20e+24 1.22e+13
---------------------------------------------------------------
Now, because I wanted 3 decimals, I modified the command line to:
tabstat D1, statistics( mean sd var median ) by(Group) columns(statistics) longstub format(%10.3f)
And get the following results:
Group variable | mean sd variance p50
----------------------+----------------------------------------
1 D1 | 1.263e+13 1.079e+12 1.165e+24 1.260e+13
2 D1 | 1.146e+13 2.642e+12 6.983e+24 1.200e+13
3 D1 | 1.209e+13 6.198e+11 3.841e+23 1.210e+13
4 D1 | 1.221e+13 6.556e+11 4.298e+23 1.205e+13
----------------------+----------------------------------------
Total D1 | 1.210e+13 1.484e+12 2.203e+24 1.215e+13
---------------------------------------------------------------
Variance for group 1 is 1.165E+24, rounded to 1.16E+24 in the first table. It should be rounded to 1.17E+24. I've tried different format options but nothing changes. This happens on other statistics of the same kind when Stata rounds a number ending in 5. Is there a way to force Stata to round as it should be? I am using Stata 14 but had the same problem with Stata 13.1.
Has anybody had the same problem or does anybody know if this is merely because my command is not correct or if this is a bug?
Thank you,
Mathias
Comment