# st: AW: Something wrong with the -count- option in the -egen-?

 From "Martin Weiss" To Subject st: AW: Something wrong with the -count- option in the -egen-? Date Thu, 13 Aug 2009 10:49:22 +0200

```<>

Nothing is wrong, luckily... As -h egen- says about the -count- option: "
creates a constant ... containing the number of nonmissing observations of
exp."

So the surprising result of your last line is easily explained: The
-expression- fed to -count- evaluates to nonmissing -either 0 or 1- for
every one of those five rows of your dataset, and -count- picks up this
number. All it cares about is the fact that the expression is non-missing,
not its content. If you want to -count-, use the standalone -count-...

*************
clear
input x
1
2
3
5
.
end
egen y=count(x)
egen yy=count(x>2)
egen yyy=count(x==2)
//another xmpl,
//20 is not even in the list of values
egen yyyy=count(x==20)
//the following dummy is counted
//it has 5 non-missing entries...
gen byte dummy=x==20
l,noobs
//stand alone -count-
cou if x==2
*************

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von gjhxmu@sina.com
Gesendet: Donnerstag, 13. August 2009 10:37
An: statalist
Betreff: st: Something wrong with the -count- option in the -egen-?

I typed the following in the stata and found -count- option didn't work
well.

Anything wrong?

clear
input x
1
2
3
5
.
end
egen y=count(x)
egen yy=count(x>2)
egen yyy=count(x==2)
l,noobs

+------------------+
| x   y   yy   yyy |
|------------------|
| 1   4    5     5 |
| 2   4    5     5 |
| 3   4    5     5 |
| 5   4    5     5 |
| .   4    5     5 |
+------------------+

Thank you for any help!

Best regards,
Rose

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```