Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: question about egen


From   Shige Song <[email protected]>
To   [email protected]
Subject   Re: st: question about egen
Date   Fri, 18 Apr 2003 00:24:18 -0700

Hi Gary,

This is exactly what I need, thanks!

Shige


The "(exp)" just indicates that Stata is looking for a valid Stata
expression here.  The logical expressions you have used are valid.

The problem is that the egen count() function is not doing what you
might logically expect: it is not counting the number of observations
for which the expression is "true".  Rather it is counting the number of
observations for which the expression evaluates to a non-missing result
(look closely at either the help or the manual for the egen count
function.).  When the logical expression evaluates to "false" (i.e.
zero) the result is nevertheless non-missing, and is thus "counted".

However, you should be able to achieve the result you want using the
egen -sum()- function using an argument which is a logical expression
evaluating to either 1 (true) or 0 (false) as in your example.

I.e.
        egen nm = sum(GENDER == 1), by(CITY)
        egen nw = sum(GENDER == 2), by(CITY)
        egen np = sum(GENDER ~= .), by(CITY)

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



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