Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: sum up many variables with missing values across columns


From   Austin Nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: sum up many variables with missing values across columns
Date   Tue, 20 Sep 2011 10:09:50 -0400

Daifeng He <dhe.statlist@gmail.com>:
You can use a loop for a varlist:

g s=0
foreach v of var vary-varzz {
 qui replace s=s+`v'
 }

Or:

egen s=rowtotal(vary-varzz)
egen c=rownonmiss(vary-varzz)
replace s=. if c<100

On Mon, Sep 19, 2011 at 1:59 PM, Daifeng He <dhe.statlist@gmail.com> wrote:
> Hi there,
>
> I am trying to sum up say 100 variables across columns, but many of
> the 100 variables have missing values. And I want the sum to be
> missing if any of the 100 variables is missing.   -rowtotal- does not
> work because it treats missing values as 0; even with the option -,
> missing-, it generates a missing value only when all the 100 variables
> are missing.
>
> Does anybody know how to do this efficiently instead of typing varx+
> vary+ var z+... varxx+varyy+varzz?  My variables do not have a common
> stub in the variable names so I cannot use a loop.
>
> Thanks for the help.
>
> Daifeng

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index