Xiangping JIA wants to add some variables, but when one is missing the
sum becomes missing.
This is standard behavior. However, egen's rowtotal() function does the
trick (in Stata 8 the name is rsum().
clear
input index var1 var2 var3
1 . 1 1
2 1 1 .
3 . 1 1
end
generate var4=var1+var2+var3
egen var5=rowtotal(var1-var3)
. list
+------------------------------------------+
| index var1 var2 var3 var4 var5 |
|------------------------------------------|
1. | 1 . 1 1 . 2 |
2. | 2 1 1 . . 2 |
3. | 3 . 1 1 . 2 |
+------------------------------------------+
Hope this helps
Svend
__________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone: +45 8942 6090
Home: +45 8693 7796
Email: [email protected]
__________________________________________
*
* 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/