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

 From gjhxmu@sina.com To statalist Subject Re: st: AW: AW: Something wrong with the -count- option in the -egen-? Date Thu, 13 Aug 2009 17:15:55 +0800

```Martin，

Thank you for your help, and now I know the inner rationale for -count- in the -egen-.

The -total- option is helpful.

BTW, what is the most value for -count- option in the -egen- ?

I can get r(N) quickly after stand alone -count- .

Best regards,

Rose.

----- Original Message -----
From: Martin Weiss <martin.weiss1@gmx.de>
To: <statalist@hsphsun2.harvard.edu>
Subject: st: AW: AW: Something wrong with the -count- option in the -egen-?
Date: 2009-8-13 17:02:02

<>

BTW, the standalone -count- command leaves "r(N)" behind, so you can process
the number further. If you want it in your dataset, you can use -egen,
total()-

*************
clear
input x
1
2
3
5
.
end

egen yyy=/*
*/ total(x==2)
list, noobs

*************

HTH
Martin

-----Urspr黱gliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Donnerstag, 13. August 2009 10:49
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: Something wrong with the -count- option in the -egen-?

<>

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黱gliche 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/

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