Bill TP
Bill TP

Reputation: 1097

Stata: Variable type (8-digit numbers)

input a
88888888
99999999
end
export excel a.xlsx, replace

Then, if I open the excel file, the numbers are shown as 8.89e+07 and 1.00e+08. How can I restore these to the original numbers. Do I have to do this in Excel? Is there any way to prevent Stata from converting those numbers to the "scientific" format?

Upvotes: 0

Views: 925

Answers (1)

Nick Cox
Nick Cox

Reputation: 37208

The effect of your input command is to read those numbers into variables of float type. But there aren't enough bits in a float to hold 99999999 exactly. This is well documented.

See e.g. the help for data types:

"floats have about 7 digits of accuracy; the magnitude of the number does not matter. Thus, 1234567 can be stored perfectly as a float, as can 1234567e+20. The number 123456789, however, would be rounded to 123456792. In general, this rounding does not matter.

If you are storing identification numbers, the rounding could matter. If the identification numbers are integers and take 9 digits or less, store them as longs; otherwise, store them as doubles. doubles have 16 digits of accuracy."

So you degraded your data by using an inappropriate data type. That is the issue, not export excel.

Upvotes: 2

Related Questions