Statalist


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

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


From   [email protected]
To   statalist<[email protected]>
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 <[email protected]>
To: <[email protected]>
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: [email protected]
[mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Donnerstag, 13. August 2009 10:49
An: [email protected]
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: [email protected]
[mailto:[email protected]] Im Auftrag von [email protected]
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/



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