[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Eva Poen" <eva.poen@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Re: saving memory local vs usual variable |

Date |
Tue, 7 Oct 2008 20:22:29 +0100 |

Kit, 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 2008/10/7 Christopher Baum <baum@bc.edu>: > < > > Eva provides good advice on this topic but this is a bit misguided. If you > save a scalar (such as r(mean) from -su-) to a local you get > > scalars: > r(N) = 74 > r(sum_w) = 74 > r(mean) = 6165.256756756757 > > . local mu = r(mean) > > . di "`mu'" > 6165.256756756757 > > You can even do arithmetic: > > . local mu = `mu' + 1 > > . di "`mu'" > 6166.256756756757 > > What is happening is that the scalar is storing, with maximum precision, the > numeric value as a binary number. The local is taking that binary number's > decimal representation and storing it as a string, so that when I ask for > the value of "mu" I get the full number of digits stored therein. As is > evident here, it clearly is not the case that the local is losing digits of > precision. But as Eva suggests, if you're trying to store numbers, storing > them as scalars (as -su- does) rather than locals makes sense. Just be > careful with their names so you do not collide with other objects in the > same namespace. > > > 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 4, 2008, at 2:33 AM, Eva wrote: > >> >> Note also the availability of scalars (-help scalar-) which can save >> numbers in higher precision than local macros. > > * > * 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/ > * * 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/

**References**:**st: Re: saving memory local vs usual variable***From:*Christopher Baum <baum@bc.edu>

- Prev by Date:
**st: RE: Updating user-supplied code / mca example** - Next by Date:
**Re: st: Generalized Sign Test** - Previous by thread:
**st: Re: saving memory local vs usual variable** - Next by thread:
**st: Re: saving memory local vs usual variable** - Index(es):

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