<>
Forget this solution, I read "highest" instead of "most frequent". Sorry!
Hopefully this is still helpful to you!
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Montag, 16. November 2009 22:33
An: [email protected]
Betreff: st: AW: Create a flag variable for 10 most frequent values
<>
*************
clear*
//construct data
set obs 10000
gen dx=_n
//5000 unique values
sample 5000, count
//sort on dx
sort dx
//give the last 10 values a "1"
gen byte flag=_n>4990
//let`s see
l in -20/l
//tabulation of "flag"
ta flag
//properties of "dx" for flag "1" or "0"
table flag, c(freq mean dx min dx max dx)
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Cohen, Elan
Gesendet: Montag, 16. November 2009 22:25
An: '[email protected]'
Betreff: st: Create a flag variable for 10 most frequent values
Hi all,
I have a string variable dx that represents a patient's diagnosis (about
5,000 unique values). I'd like to create a "top 10 flag" that equals 1 if
dx is one of the top 10 most frequent diagnoses and 0 otherwise.
I'm not even sure where to begin. If someone could point me in the right
direction, I'd be grateful. Stata 10, Windows XP
Thank you,
- Elan
*
* 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/