[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
David Bell <dcbell@iupui.edu> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: SUM question |

Date |
Thu, 15 May 2008 08:39:03 -0400 |

Dear Satomi,

You have surmised that -egen newvar = rowtotal(var1 var2)- treats missing values as zero. I do not believe this is strictly correct. The command just sums the values that it has (thus not using a variable in a sum is the same as treating it as zero). This is why I always use -rowmean- instead of -rowtotal-. Thus when there is a missing value, you get the mean of the remaining values (they are not treated as zeros).

Dave

====================================

David C. Bell

Professor of Sociology

Indiana University Purdue University Indianapolis (IUPUI)

(317) 278-1336

====================================

On May 15, 2008, at 12:31 AM, Yamamoto, Satomi wrote:

Hello,

Thank you very much for the prompt reply.

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.

Do you have any ideas? It would be great if I could get help on this.

Sincerely,

Satomi

-----Original Message-----

From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu ] On Behalf Of Richard Williams

Sent: Wednesday, May 14, 2008 11:47 PM

To: statalist@hsphsun2.harvard.edu; statalist@hsphsun2.harvard.edu

Subject: Re: st: SUM question

At 10:29 PM 5/14/2008, Yamamoto, Satomi wrote:

Hello,

I'm wondering if anybody knows the Stata command that is equivalent to

the following SPSS command:

compute newvar= sum(var1, var2).

exe.

The SUM function in SPSS allows you to keep cases with missing values

instaead of droppoing them. It's one way of preventing listwise

deletion. It would be great if I can get help with this.

Sincerely,

Satomi

egen newvar = rowtotal(var1 var2) ------------------------------------------- Richard Williams, Notre Dame Dept of Sociology OFFICE: (574)631-6668, (574)631-6463 HOME: (574)289-5227 EMAIL: Richard.A.Williams.5@ND.Edu WWW: http://www.nd.edu/~rwilliam * * 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/

* * 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/

**Follow-Ups**:**RE: st: SUM question***From:*"n.j.cox@durham.ac.uk" <n.j.cox@durham.ac.uk>

**RE: st: SUM question***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: SUM question***From:*"Yamamoto, Satomi" <syamamot@ad.uiuc.edu>

**Re: st: SUM question***From:*Richard Williams <Richard.A.Williams.5@ND.edu>

**RE: st: SUM question***From:*"Yamamoto, Satomi" <syamamot@ad.uiuc.edu>

- Prev by Date:
**st: Re: infix problem** - Next by Date:
**st: Problems with STATA 10, e.g. saving file causes variables to dropout** - Previous by thread:
**RE: st: SUM question** - Next by thread:
**RE: st: SUM question** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |