This is the solution where I can lean some more of Stata coding...
Thank you!
On Jun 5, 2008, at 2:55 PM, Nick Cox wrote:
A solution from first principles is
gen total = 0
qui foreach v of var varA varB varC {
replace total = total + `v' if !missing(`v')
}
Notice that -total- ends up with 0 if all are missing.
Suppose you want
missing if all are missing
the total of non-missings otherwise
That is only a little more complicated.
gen total = .
qui foreach v of var varA varB varC {
replace total = cond(missing(total), `v', total + `v') if
!missing(`v')
}
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/