Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: RE: Use 'tab' function to tabulate the reversed data


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: RE: Use 'tab' function to tabulate the reversed data
Date   Mon, 24 Jan 2011 19:54:07 +0000

There's naturally also an ugly solution, perhaps worth remembering only as very dirty, but very quick compared with trying to remember which more complicated code does it. 

gen negmk = -mk
tab negmk 

You could also wrap this up in a program:

. sysuse auto, clear 
(1978 Automobile Data)

. preserve

. contract mpg, perc(_percent) cfreq(_cfreq) cpercent(_cpercent) 

. gsort -mpg 

. list, noobs 

  +--------------------------------------------+
  | mpg   _freq   _cfreq   _percent   _cperc~t |
  |--------------------------------------------|
  |  41       1       74       1.35     100.00 |
  |  35       2       73       2.70      98.65 |
  |  34       1       71       1.35      95.95 |
  |  31       1       70       1.35      94.59 |
  |  30       2       69       2.70      93.24 |
  |--------------------------------------------|
  |  29       1       67       1.35      90.54 |
  |  28       3       66       4.05      89.19 |
  |  26       3       63       4.05      85.14 |
  |  25       5       60       6.76      81.08 |
  |  24       4       55       5.41      74.32 |
  |--------------------------------------------|
  |  23       3       51       4.05      68.92 |
  |  22       5       48       6.76      64.86 |
  |  21       5       43       6.76      58.11 |
  |  20       3       38       4.05      51.35 |
  |  19       8       35      10.81      47.30 |
  |--------------------------------------------|
  |  18       9       27      12.16      36.49 |
  |  17       4       18       5.41      24.32 |
  |  16       4       14       5.41      18.92 |
  |  15       2       10       2.70      13.51 |
  |  14       6        8       8.11      10.81 |
  |--------------------------------------------|
  |  12       2        2       2.70       2.70 |
  +--------------------------------------------+

. restore

Nick 
[email protected] 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 24 January 2011 19:34
To: '[email protected]'
Subject: st: RE: Use 'tab' function to tabulate the reversed data

Phil Ender's -rtab- does this. Use -findit rtab- to find it. 

(I was surprised that more things don't (seem to). But one nice solution is fine!) 

Nick 
[email protected] 

keeler james

I wonder if anyone can help. For data tabulation of a field in a dataset you can use the command 'tab mk' to list the frequency table as folows. What if we want to do a 'tab' for reversed mk, i.e. starting the largest number first to the smallest number last? In this case it is 112, 109, 106.7, ..., 22, 15.3 1nd 6.7? many thanks.

calchas


. tab mk


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index