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

Re: st: RE: Tables, percentage without decimals


From   "Michael and Rita C. Carlberg" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Tables, percentage without decimals
Date   Wed, 17 Nov 2004 03:58:05 -0800 (PST)

Nick,

Thank you very much for your suggestions, I will try
both of them out.

Michael

--- Nick Cox <[email protected]> wrote:

> I don't know of a canned way to do 
> this in official Stata, but it can 
> be approached otherwise. Two 
> possibilities are (1) -groups- 
> from SSC (2) writing your own program. 
> 
> . sysuse auto 
> 
> . ssc inst groups 
> 
> . groups mpg, show(f p P) format(%6.0f)
> 
>   +------------------------------+
>   | mpg   Freq.   Percent   Cum. |
>   |------------------------------|
>   |  12       2         3      3 |
>   |  14       6         8     11 |
>   |  15       2         3     14 |
>   |  16       4         5     19 |
>   |  17       4         5     24 |
>   |------------------------------|
>   |  18       9        12     36 |
>   |  19       8        11     47 |
>   |  20       3         4     51 |
>   |  21       5         7     58 |
>   |  22       5         7     65 |
>   |------------------------------|
>   |  23       3         4     69 |
>   |  24       4         5     74 |
>   |  25       5         7     81 |
>   |  26       3         4     85 |
>   |  28       3         4     89 |
>   |------------------------------|
>   |  29       1         1     91 |
>   |  30       2         3     93 |
>   |  31       1         1     95 |
>   |  34       1         1     96 |
>   |  35       2         3     99 |
>   |------------------------------|
>   |  41       1         1    100 |
>   +------------------------------+
> 
> -groups- was discussed in excruciating detail in 
> 
> Problems with tables, Part II. 
> Stata Journal 3(4):420--439 (2003)
> reviews three user-written commands (tabcount,
> makematrix,
> and groups) as different approaches to tabulation
> problems
> 
> Knitting a program yourself is also 
> possible, and easier than you might think given 
> some use of basic Stata and -tabdisp-. Half the 
> code needed is already on display at 
> http://www.stata.com/support/faqs/data/tabdisp.html
> 
> program michaeltab, sortpreserve
> 	version 8 
> 	syntax varname [if] [in] 
> 	marksample touse, strok 
> 	tempvar freq pc cumpc 
> 	bysort `touse' `varlist': gen long `freq' = _N 
> 	qui count if `touse' 
> 	gen double `pc' = 100 * `freq' / r(N) 
> 	by `touse' `varlist' : gen double `cumpc' = `pc' *
> (_n == 1) 
> 	qui by `touse' : replace `cumpc' = sum(`cumpc') 
> 	qui replace `pc' = round(`pc') 
> 	qui replace `cumpc' = round(`cumpc')
> 	label var `freq' "Frequency" 
> 	label var `pc' "Percent" 
> 	label var `cumpc' "Cum." 
> 	tabdisp `varlist' if `touse', c(`freq' `pc'
> `cumpc')
> end
> 
> . michaeltab mpg
> 
> ----------------------------------------------
> Mileage   |
> (mpg)     |  Frequency     Percent        Cum.
> ----------+-----------------------------------
>        12 |          2           3           3
>        14 |          6           8          11
>        15 |          2           3          14
>        16 |          4           5          19
>        17 |          4           5          24
>        18 |          9          12          36
>        19 |          8          11          47
>        20 |          3           4          51
>        21 |          5           7          58
>        22 |          5           7          65
>        23 |          3           4          69
>        24 |          4           5          74
>        25 |          5           7          81
>        26 |          3           4          85
>        28 |          3           4          89
>        29 |          1           1          91
>        30 |          2           3          93
>        31 |          1           1          95
>        34 |          1           1          96
>        35 |          2           3          99
>        41 |          1           1         100
> ----------------------------------------------
> 
> Admittedly, the bottom line is no bottom line 
> (with totals). As in another thread, the code
> is there for you to modify to taste. 
> 
> Nick 
> [email protected] 
> 
> Michael and Rita C. Carlberg
>  
> > This is probably something easy to solve, but I
> > haven't found a solution, looking at FAQ or
> previous
> > messagee to the list.
> > 
> > I simply want Stata to show the result without
> > decimals, when I make a table, for example:
> > 
> > tabulate fraga16
> > 
> >    Fraga16 |      Freq.     Percent        Cum.
> > ------------+-----------------------------------
> >           1 |        137       19.97       19.97
> >           2 |        353       51.46       71.43
> >           3 |         92       13.41       84.84
> >           4 |         71       10.35       95.19
> >           5 |         20        2.92       98.10
> >           9 |         10        1.46       99.56
> >         999 |          3        0.44      100.00
> > ------------+-----------------------------------
> >       Total |        686      100.00
> > 
> > 
> > I want the result to look something like this:
> > 
> >    Fraga16 |      Freq.     Percent        Cum.
> > ------------+-----------------------------------
> >           1 |        137       20          20
> >           2 |        353       51          71
> >           3 |         92       13          85
> >           4 |         71       10          95
> >           5 |         20        3          98
> >           9 |         10        1         100
> >         999 |          3        0         100
> > ------------+-----------------------------------
> >       Total |        686      100
> > 
> 
> *
> *   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/
> 



		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 

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