Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
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: [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/



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