Statalist


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

st: Re: saving memory local vs usual variable


From   Christopher Baum <[email protected]>
To   [email protected]
Subject   st: Re: saving memory local vs usual variable
Date   Tue, 7 Oct 2008 14:42:48 -0400

< >
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/



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