# st: Re: How to sum several scalars

 From "P. Wilner" To statalist@hsphsun2.harvard.edu Subject st: Re: How to sum several scalars Date Mon, 12 Nov 2007 21:36:30 -0500

```On Nov 12, 2007 4:11 PM, <tiago.pereira@incor.usp.br> wrote:
> Dear all,
>
> Suppose I have 10 scalars, which contain some statistic of 10 variables.
> These scalars are: statistic1, statistic2..... statistic10.
>
> How one can sum a set of these scalars? I mean, letīs assume I want to sum
> statistic3 to statistic7. Ho do one do that?
>
>
> Tiago
>
> P.S. I would like to thank Kit and Joseph for their help on my last post.
> Thank you very much.
>

I think the example below may do the job Tiago wants to do, though
others may have a better solution for Tiago.

** Begin example ****

* Create 10 scalars
forv i=1/10 {
scalar myscal`i'=`i'+3
di "scalar =", myscal`i'
}

* Or if you will
scalar list

* Now let's sum them
local i=1
scalar mysum=0
while `i'<=10 {
scalar mysum= mysum + myscal`i'
local i=`i'+1
}
di mysum

** End example *****

Hope this helps

--
P. Wilner Jeanty, Post-doctoral researcher
Dept. of Agricultural, Environmental, and Development Economics
The Ohio State University