Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Need clarification regarding egen total option
From
Nick Cox <[email protected]>
To
[email protected]
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
<[email protected]> 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/