Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Re: STATA mistakes divisions!
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Re: STATA mistakes divisions!
Date
Thu, 15 Mar 2012 16:43:22 +0100
On Thu, Mar 15, 2012 at 3:48 PM, Francesco Vidoli wrote:
> But therefore by default, without writing in every division "float",
> STATA mistake divisions?
> It's not only a visualization problem, we are trying to compare a SAS
> OLS regression and results simply do not add up if you calculate the
> variables of SAS or STATA ...
No, there is no mistake. This is a phenomenon known as precision, and
it is a result of the fact that computers cannot store most numbers
with infinite precision. Stata (note: not STATA) has some smart
defaults on how much precision to use for variables, computations,
scalars, etc. In short data is by default stored with less precision
(about 7-8 decimal digits) than computations (about 17-18 decimal
digits). This is smart as even the 7-8 digits is complete overkill for
real world data. Some nice examples of this can be found here:
<http://blog.stata.com/2011/06/17/precision-yet-again-part-i/>.
However if you want to do computations with variables than you want to
overwrite this default, as many tiny rounding errors can start to add
up to a large or at least noticeable error. You do so as follows:
gen double varname = expression
The key part is -double-, that tells you that the variable is supposed
to be stored in double precision, i.e. about 18 decimal digits, which
corresponds to the precision used by SAS and others. This is also what
Stata programs do internally when they are using variables to do
computations. Some computations are even done in quad precision
(approximately 34 decimal digits).
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/