|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: SUM question
Thank you, Svend.
I appreciate your help.
Satomi
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Svend Juul
Sent: Thursday, May 15, 2008 2:00 AM
To: [email protected]
Subject: Re: st: SUM question
Satomi wrote:
...
I think egen newvar = rowtotal(var1 var2) is equivalent to replacing missing values with 0(zero).
The SUM function in SPSS adds cases in the variable where at least one observation is valid:
Var 1 Var2
1 4
3 5
4 5
5 8
. 5
. .
When compute newvar= sum(var1, var2). is used, there will be 1 missing case.
When compute newvar= var1+var2. is used, there are 2 missing cases.
=================================================================
You can gain control with -egen-'s -rowmiss()- and -rownonmiss()-
functions:
. generate plusvar = var1+var2
. egen egenvar1 = rowtotal(var1 var2)
. egen nomiss = rownonmiss(var1 var2)
. generate egenvar2 = egenvar1 if nomiss>0
. list , clean
var1 var2 plusvar egenvar1 nomiss egenvar2
1. 1 4 5 5 2 5
2. 3 5 8 8 2 8
3. 4 5 9 9 2 9
4. 5 8 13 13 2 13
5. . 5 . 5 1 5
6. . . . 0 0 .
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/
*
* 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/