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

Re: st: summing variables

From   "Austin Nichols" <>
Subject   Re: st: summing variables
Date   Thu, 26 Jul 2007 17:53:14 -0400

There is a subtle distinction which may have gotten lost in the
shuffle--Maarten's approach (you have to insert an "=0" after "gen
double totalmg" in his example to make it work) puts missing for the
total if any of the components are missing, whereas the -egen-
approach of Ricardo assumes any missings are zero.  I prefer Maarten's
approach for that reason.


set seed 1234567
set obs 10
forv i=1/10 {
qui g mg_`i'=uniform() if uniform()>.1
egen totalrsum=rsum(mg_1-mg_10)
gen double totalmg=0
foreach var of varlist mg_* {
qui replace totalmg = totalmg + `var'
li total*, noo

On 7/26/07, P chrisman <> wrote:
egen totalmg=rsum(mg_1-mg_108) worked great! Thanks for the assistance. pc
*   For searches and help try:

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