Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Is there a way to display a table by order of frequency?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Is there a way to display a table by order of frequency?
Date   Fri, 9 Jan 2004 14:11:44 -0000

In Stata 8, -tabulate- has a -sort- option. 

For example, 

. sysuse auto
. gen manuf = word(make,1) 
. tab manuf 

      manuf |      Freq.     Percent        Cum.
------------+-----------------------------------
        AMC |          3        4.05        4.05
       Audi |          2        2.70        6.76
        BMW |          1        1.35        8.11
      Buick |          7        9.46       17.57
       Cad. |          3        4.05       21.62
...
      Volvo |          1        1.35      100.00
------------+-----------------------------------
      Total |         74      100.00

. tab manuf , sort

      manuf |      Freq.     Percent        Cum.
------------+-----------------------------------
      Buick |          7        9.46        9.46
       Olds |          7        9.46       18.92
      Chev. |          6        8.11       27.03
      Merc. |          6        8.11       35.14
      Pont. |          6        8.11       43.24
      Plym. |          5        6.76       50.00
     Datsun |          4        5.41       55.41
      Dodge |          4        5.41       60.81
... 
      Volvo |          1        1.35      100.00
------------+-----------------------------------
      Total |         74      100.00


Otherwise, this problem has been addressed 
by various user-written programs. Two I know 
about are -tabsort- and -groups- on SSC. 

There is pertinent discussion in 
"Problems with tables, Part II" Stata Journal
3(4):420--439 (2003). 

Nick 
[email protected] 

Loreto Carmona
 
> When tabulating a categorical string variable with many 
> levels, I want
> sometimes to see the results ordered by frequency, rather than in
> alphabetical order.
> 
> In long tables I don't feel like changing the label order 
> in the do file
> every time I get un update of the data file (with newer levels).

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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