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

st: Re: saving memory local vs usual variable

From   Christopher Baum <>
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

                  r(N) =  74
              r(sum_w) =  74
               r(mean) =  6165.256756756757

. local mu = r(mean)

. di "`mu'"

You can even do arithmetic:

. local mu = `mu' + 1

. di "`mu'"

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
An Introduction to Modern Econometrics Using Stata:

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:

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