[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <[email protected]> |

To |
<[email protected]> |

Subject |
RE: st: AW: How to compute sigma or sum |

Date |
Sun, 3 Feb 2008 17:04:02 -0000 |

It seems that this doesn't answer the original question, and I am not sure what does. But as -summarize- has been mentioned, correctly, as a good way to get the sum of a variable, let me emphasise that if efficiency is of concern, then -summarize, meanonly- is more efficient. The StataCorp option name -meanonly- may well mislead here, as the option in question does more than calculate means. If more detail is needed, see SJ-7-3 st0135 Stata tip 50: Efficient use of summarize Q3/07 SJ 7(3):438--439 tip on using the meanonly option of summarize to more quickly determine the mean and other statistics of a large dataset. Also in what follows, Sergiy has local sigma=r(sum) display `sigma' There's no need for the indirection for immediate display, as display r(sum) will do it in one. For the later use which Sergiy has in mind, storage naturally is important, but a scalar is more precise than a local. tempname sigma scalar `sigma' = r(sum) Nick [email protected] Sergiy Radyakin Martin Weiss has shown an example where a new variable is created and its values for all observations are set to the sum of the values of another variable. Although indeed this provides the desired sum, it is rather inefficient in terms of both memory use and computational performance. To find a sum of the values of a variable, use summarize x display r(sum) If need to reuse this value later in your program, store it in a local: local sigma=r(sum) display `sigma' A number of other related statistics (min, max, sd) can be obtained in a similar fashion. Type return list after summarize (or any other command) to see the results available. * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Re: comparison of OLS and fixed-effect regression coefficients***From:*Kit Baum <[email protected]>

**st: How to compute sigma or sum***From:*adiwan fahlan <[email protected]>

**Re: st: AW: How to compute sigma or sum***From:*"Sergiy Radyakin" <[email protected]>

- Prev by Date:
**Fwd: Re: st: GEE or svy:logit** - Next by Date:
**st: Re: rensheet** - Previous by thread:
**Re: st: AW: How to compute sigma or sum from a calculation** - Next by thread:
**st: GEE or svy:logit** - Index(es):

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