[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Format of numeric results
> got stuck with a seemingly simple problem. Tried to generate a
> variable using existing variables in the data set and a couple of
> arithmetic operations. However, manual double checks reveal that
> stata comes up the wrong result. Because the results are fairly
> large (the width is 12) I tried all kinds of formats but
> failed to get the
> right results. I wonder if there is any global command that changes
> the way stata deals with large numbers?
> the code is
> gen x=(((z*1000000000)+y)*10)+d-910
> where z, y, and d are variables in the data set (y is large
> and none
> of the variables has got digits).
The best manual double check here is the Manual:
see explanations of the -double- and -long- data
types. The on-line help for -datatypes- also helps.
That is, unless you earlier
. set type double
. set type long
(which I would _not_ recommend), Stata is by
default trying to put your results in a -float-
variable, and that is my guess why Stata appears
to be producing incorrect results. Although
the maximum allowed in a -float- may seem enough
to store what you want, there may not be enough
bits to store data without loss of precision.
If you know that the results must always be
large integers (which I think is what you have
in mind, use
. gen long x = ...
Alternatively, if fractional parts may arise,
. gen double x = ...
* For searches and help try: