[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: data representation
K.I. , I hope this is useful to get a solution for your problem.
Type help datatypes to get the following info:
Precision of numeric storage types
floats have about 7 digits of accuracy; the magnitude of the number does not
Thus, 1234567 can be stored perfectly as a float, as can 1234567e+20. The
123456789, however, would be rounded to 123456792. In general, this rounding
If you are storing identification numbers, however, the rounding could matter.
identification numbers are integers and take 9 digits or less, store them as
otherwise, store them as doubles. doubles have 16 digits of accuracy.
Stata stores numbers in binary and this has a second effect on numbers less than
has no perfect binary representation just as 1/11 has no perfect decimal
In float, .1 is stored as .10000000149011612. Note that there are 7 digits of
just as with numbers larger than 1. Stata, however, performs all calculations
precision. If you were to store 0.1 in a float called x and then ask, say,
x==.1", there would be nothing in the list. The .1 that you just typed was
double, with 16 digits of accuracy (.100000000000000014...) and that number is
to 0.1 stored with float accuracy.
One solution is to type "list if x==float(.1)". The float() function rounds its
to float accuracy; see help functions. The other alternative would be store
your data as
double, but this is probably a waste of memory. Few people have data that is
1 part in 10 to the 7th. Among the exceptions are banks, who keep records
accurate to the
penny on amounts of billions of dollars. If you are dealing with such financial
store your dollar amounts as doubles. See [U] 16.10 Precision and problems
Manual: [U] 15 Data,
[U] 16.10 Precision and problems therein,
[R] data types
On-line: help for compress, encode, format, recast
My best regards,
* For searches and help try: