Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[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 <[email protected]>
To
[email protected]
Subject
Re: st: sum up many variables with missing values across columns
Date
Tue, 20 Sep 2011 10:09:50 -0400
Daifeng He <[email protected]>:
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 <[email protected]> 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/