Hi all, I'm using Stata 14 and wish to round data in one of my variables to 1 dp. I shall be retaining the original variable but for export purposes I need to display only 1 dp in the output file. However when I use -round- I end up getting, what appears to me, spurious information and extra dp information that I thought and expected to be discarded. This is how my data are set up:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str9 AreaCode float p50
"P81032" 2.592737
"B86024" 2.4379544
"C82018" 2.123174
"C88656" 3.6908944
"G85027" 2.5807104
"J82622" 2.200846
"B86054" 2.3315396
"N84018" 4.18
"M81074" 4.1080074
end
I then run the code
Code:
generate p50_rounded = round(p50,0.1)
On initial inspection the code seems to have worked, however if you inspect the data in the data editor I find for the first record ("P81032") the value for p50_rounded is 2.5999999 with Stata displaying 2.6. When I export to Excel, the value that gets exported is the 2.5999999.
What can I do to force Stata to export what is displayed?
Thanks in advance
0 Response to True discard of precision with round
Post a Comment