Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Format of numeric results


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Format of numeric results
Date   Sat, 26 Oct 2002 15:42:57 +0100

Axel Heitmueller
>
> 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

or

. 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,
use

. gen double x = ...

Nick
n.j.cox@durham.ac.uk

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index