Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: sum of variable


From   baum <[email protected]>
To   [email protected]
Subject   st: Re: sum of variable
Date   Thu, 15 Aug 2002 08:50:51 -0400

--On Thursday, August 15, 2002 2:33 -0400 Glena wrote:

Could you, please, let me know how to obtain the scalar for the value of
the  column sum? I need the value I get using "egen sum(x)", but not the
column of  these values, but just a single number which stata would terat
as a scalar. Thank you.
egen sum is not the right construct (unless you want a column containing the scalar, and you don't). It is also useful to remember the difference between egen sum and gen sum; the latter will produce the running sum, and the scalar you want is in the last obs. But either is inefficient because they involve defining a new variable that you do not want. Rather,

summ price, meanonly [apply if or in as desired]
scalar sigma = r(sum)
di sigma

will avoid creating the new variable, and with 'meanonly' does the calculation efficiently and quietly. If you 'return list' after summ you can see what all is there for the snarfing.

Kit

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




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