|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Re: saving memory local vs usual variable
< >
Eva is correct. Two objects that differ by 10^-16 are not identical.
The point I was making that in practice one can usually consider them
to be so. From a computer science standpoint, as I indicated earlier,
scalars hold their contents in binary and avoid conversion to and from
string form (which is what lives in a macro). In practice one should
never test something that is held as a real number for equality, as
many Stata FAQs and Stata Tips suggest. But my original point is that
storing something as a macro---for instance, a regression coefficient,
held internally with ~15-digit accuracy---will be just about as
accurate as storing it as a scalar. Yes, the macro version will be an
approximate representation, but most of us don't sweat getting the
15th digit right. As was once said (by Norbert Weiner to John von
Neumann, I recall) "Economics is a one or two digit science".
Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
On Oct 8, 2008, at 02:33 , Eva wrote:
thank you for your reply. I have in front of me my old NetCourse 152
(Stata 8!) which says:
"Scalars give us a way of obtaining a perfect binary copy of the
binary number in ...".
Later on, it says: "In short, you must use scalars if you plan to
obtain a value from the data and then, later, test the data for exact
equality with that value. In all other cases, use scalars when you
need greater accuracy."
And here is an example showing that the local macro is not the same as
the scalar. Am I misunderstanding something completely?
Thanks,
Eva
. sysuse auto, clear
(1978 Automobile Data)
. replace foreign = 1.10101 if foreign==0
foreign was byte now float
(52 real changes made)
. replace foreign = 1.20101 if foreign==1
(22 real changes made)
. sum foreign
Variable | Obs Mean Std. Dev. Min Max
- -------------
+--------------------------------------------------------
foreign | 74 1.13074 .0460189 1.10101 1.20101
. local min = r(min)
. scalar Min = r(min)
. count if foreign==`min'
0
. count if foreign==Min
52
. di `min' - Min
- -2.220e-16
*
* 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/