Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: FW: Interval Tabbing?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: FW: Interval Tabbing?
Date   Wed, 23 Jan 2008 19:34:44 -0000

Although for any reasonable (i.e. equal) binning, doing it directly is
probably easiest: 

. sysuse auto 
. gen mpg2 = string(4 * floor(mpg/4)) + "-"
. tab mpg2

       mpg2 |      Freq.     Percent        Cum.
------------+-----------------------------------
        12- |         10       13.51       13.51
        16- |         25       33.78       47.30
        20- |         16       21.62       68.92
        24- |         12       16.22       85.14
        28- |          7        9.46       94.59
        32- |          3        4.05       98.65
        40- |          1        1.35      100.00
------------+-----------------------------------
      Total |         74      100.00

I suggested some time ago to StataCorp that -floor()- (and, for that
matter, -ceil()-) could take an optional second argument: thus
-floor(mpg, 4)- would be 4 * floor(mpg/4), as above. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 23 January 2008 19:07
To: [email protected]
Subject: st: FW: Interval Tabbing?

When I said -tabcount-, I really meant -tabcond-. 

-----Original Message-----
From: Nick Cox 
Sent: 23 January 2008 19:04
To: '[email protected]'
Subject: RE: Interval Tabbing?


At worst, this is two (or three) steps, 

1. create categories 

(2. label them nicely) 

3. tabulate 

But it can be compressed to one step: 

. findit tabcount 

. ssc inst tabcount 

The help file for -tabcount- also has some examples of solutions that
don't entail using -tabcount-. 

Nick 
[email protected] 

Rachel

What I'm looking to do is put a histogram in table form: That is, I'd
like a table showing me how many (and what percentage) of a variable
falls within intervals whose width I specify.

So for example, if X has values 2,3,5,7, and I specified an interval
of width for, the resulting table would look something like:

X range   Perc
0-4         50%
>4-8         50%
8-12          0%

Is there any Stata command (or user-written module) that can do this?

*
*   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/

*
*   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