# Re: st: scalar question

 From "Radu Ban" To statalist@hsphsun2.harvard.edu Subject Re: st: scalar question Date Fri, 21 Jul 2006 15:03:23 -0400

```you can try the -egen rsum- command and then take the mean, as the sum
of means is equal to mean of sums. for example:

egen rowsum = rsum(V*)
summarize rowsum
scalar z = r(mean)
drop rowsum

```
```I am using a simple while loop statement (see below) to add the mean of each
variable in a series.  The program runs fine except if one of the variables
contains all missing values (there are reasons why I need to keep the
variables).  If, for instance, the 500th variable contains all missing
values, then the scalar (i.e., average_V`i') for the 500th variable equals a
missing value (of course), but the additive scalar (i.e., z) from that point
forward only reports missing values.   That is, my additive scalar stops
adding.  I have been programming a bypass around each of these problematic
variables, but is there a command or something that I could use instead?
Thanks!

Example:

scalar z = 0
local i = 1
while `i' <= 1000 {

summarize V`i'
scalar average_V`i'= r(mean)
scalar z= z +  average_V`i'

local i = `i' + 1
}

Assistant Professor
University of Connecticut
Department of Political Science
341 Mansfield Rd, U-1024
Storrs, CT 06269
w: (860)486-3747

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

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