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]
st: sum up many variables with missing values across columns
From
daniel klein <[email protected]>
To
[email protected]
Subject
st: sum up many variables with missing values across columns
Date
Tue, 20 Sep 2011 05:21:03 +0200
Daifeng,
I think there are many ways of doing this. One is to use -egen-s
-rowmiss- function like in
. egen hasmiss = rowmiss(var1-var100)
. egen sumup = rowtotal(var1-var100)
. replace sumup = . if hasmiss
I have an ado-file, -chm- (available from SSC), that can also be used
for this. You would have to type
. chm var1-var100 ,soft : egen sumup = rowtotal(var1-var100)
or, if you have already (e)generated the new variable
. chm var1-var100 sumup ,replace soft
Best
Daniel
---
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.
*
* 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/