Statalist


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

RE: st: bottom to top or reverse cumulative distribution in table command?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: bottom to top or reverse cumulative distribution in table command?
Date   Wed, 20 Jan 2010 12:03:30 -0000

Another elementary trick is to create a negated version of the variable and tabulate in terms of that, removing minus signs from the table via an edit. In its simplest form that requires values to be strictly positive. And any value labels would need to be edited too. 

clonevar negx = x 
replace negx = -negx 
tab negx

Nick 
[email protected] 

Nick Cox

Maarten and Martin correctly pointed out that you can re-create such tabulations for yourself from first principles. 

However, a more elaborate canned alternative is available. See -groups- from SSC. There was some discussion in 

SJ-3-4  pr0011  . . . . . . . .  Speaking Stata: Problems with tables, Part II
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/03   SJ 3(4):420--439                                 (no commands)
        reviews three user-written commands (tabcount, makematrix,
        and groups) as different approaches to tabulation problems


which is available on-line at the Stata Journal website. 

Nick 
[email protected] 

Martin Weiss

Similarly:

sysuse auto, clear
cumul rep78, generate(cumrep78) equal
gen reversecumrep78=1-cumrep78
bys rep78: egen freq=count(rep78)
bys rep78: keep if _n==1
l rep78 freq reversecumrep78

Maarten buis

--- Stefan Gawrich wrote:
> Is there any univariate table command available that displays a 
> bottom to top or reverse cumulative distribution? One example: 
> I have data on the number of vaccine doses given (0..9) and want 
> to know the percentage of cases having at least 4 or 3 or 2 doses. 

I don't know of such a program, but it is easy enough to create it.
Below is such a program -reversecum-. It gives for each value the
percentage of observations that have that value or more (excluding
missing values), it allows for -fweights- and -if- and -in- 
conditioning. 

This program will be normally available on your computer like any 
other Stata command, if you copy the line starting with 
"*! version..." and ending with "end" (inclusive) into a file 
and call it reversecum.ado and save it in your personal ado folder 
(type in Stata -adopath- to find out where that is). 

Alternatively, you can put these lines at the top of your do-file, 
and this program will than be available while running that do-file, 
like in the example below.

*-------------- begin example -----------------
program drop _all
*! version 1.0.0 MLB 20Jan2010
program reversecum
	syntax varname [if] [in] [fweight]
	marksample touse
	tempvar _freq cum r_cum
	if "`weight'" != "" {
		local wgt "[`weight'`exp']"
	}
	preserve
	contract `varlist' if `touse' `wgt', ///
	         freq(`_freq') cpercent(`cum') nomiss
	qui gen double `r_cum' = 100 - `cum'[_n-1]
	qui replace `r_cum' = 100 in 1
	format `r_cum' %8.2f
	label var `r_cum' "reverse Cum"
	tabdisp `varlist', cell(`_freq' `r_cum')
	restore
end

sysuse auto, clear
reversecum rep78
*-------------------- end example -----------------------
( For more on how to use examples I sent to statalist see:
 http://www.maartenbuis.nl/stata/exampleFAQ.html )


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index