Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Need clarification regarding egen total option


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Need clarification regarding egen total option
Date   Thu, 14 Feb 2013 01:08:25 +0000

The help for -egen- itself provides what you need. The function
-total()- (itself not an option) is explained as

total(exp) [, missing]  creates a constant (within varlist) containing
the sum of exp treating missing as 0.

The expression exp is in turn

age

age >= 18

The second expression is true or false, and therefore evaluates as 1
if true and 0 if false. The effect, as you observe, is to count.

For much more discussion, see

http://www.stata.com/support/faqs/data-management/true-and-false/

Nick

On Wed, Feb 13, 2013 at 9:49 PM, Michael Stewart
<michaelstewartresearch@gmail.com> wrote:

> I am trying to find the behaviour of the egen total function
>
> Let's see the following three commands
>
> .1) bysort fam:egen total1=total( age )              ==> this cmd sums
> the age across observations  per family
>
> 2). bysort fam:egen total2=total( age>=18 )      ==> this cmd COUNTS
> the number of nonmissing values for age per family if > 18
>
> 3). bysort fam:egen total3=total( age) if age >=18   ==> this cmd
> again sums the age across observations  per family if >18
>
> why does the total option sums the ages when the option is total( age
> )  where as gives the number of observations if total( age>=18 )
> option is present
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index