Statalist The Stata Listserver


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

Re: st: Control the dp of the percentage that is output using


From   "Eamonn O'Brien" <Eamonn.O'[email protected]>
To   <[email protected]>
Subject   Re: st: Control the dp of the percentage that is output using
Date   Tue, 17 Oct 2006 14:41:53 +0100

Thank you for the informative reply.

>>> [email protected] 17 October 2006 12:19:58 >>>
There is no option in -tabulate- for this. The FAQ

         2/02    How do I tabulate cumulative frequencies?
                 http://www.stata.com/support/faqs/data/tabdisp.html 

indicates another strategy: write your own program. A variant on
the example program given there is

program yourtab, sortpreserve
         version 8
         syntax varname [if] [in] [, Format(str)]
         marksample touse, strok
         tempvar freq pc cumpc spc scumpc
         bysort `touse' `varlist': gen long `freq' = _N
         by `touse' `varlist' : gen `cumpc' = `freq' * (_n == 1)
	  su `cumpc' if `touse', meanonly
         by `touse' `varlist': gen `pc' = 100 * `freq' / r(sum)
         qui by `touse' `varlist': replace `cumpc' = `pc' * (_n == 1)
         qui by `touse' : replace `cumpc' = sum(`cumpc')
         if "`format'" == "" local format "%3.1f"
	  qui gen `spc' = string(`pc', "`format'")
         qui gen `scumpc' = string(`cumpc', "`format'")
		
         label var `freq' "Freq."
         label var `spc'   "Percent"		
         label var `scumpc' "Cum."
         tabdisp `varlist' if `touse', c(`freq' `spc' `scumpc')
end

with sample output

. yourtab rep78

----------------------------------------------
Repair    |
Record    |
1978      |      Freq.     Percent        Cum.
----------+-----------------------------------
         1 |          2         2.9         2.9
         2 |          8        11.6        14.5
         3 |         30        43.5        58.0
         4 |         18        26.1        84.1
         5 |         11        15.9       100.0
----------------------------------------------

Compare

. tab rep78

      Repair |
Record 1978 |      Freq.     Percent        Cum.
------------+-----------------------------------
           1 |          2        2.90        2.90
           2 |          8       11.59       14.49
           3 |         30       43.48       57.97
           4 |         18       26.09       84.06
           5 |         11       15.94      100.00
------------+-----------------------------------
       Total |         69      100.00

Naturally, you may want totals too....

Another alternative is -groups- from SSC.

I guess that Roger Newson would want to
recommend his -xcontract- as yet another possible
starting point. In that case, -format- your
percent variables before a -list-.

Nick
[email protected] 

Eamonn O'Brien

Is it possible to control the displayed decimal place of the
percentage
that is output using -tabulate-? I would like to display percentage as
1
dp.
*
*   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