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

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

From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: bottom to top or reverse cumulative distribution in table command?
Date   Wed, 20 Jan 2010 11:19:35 +0100



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


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Maarten buis
Gesendet: Mittwoch, 20. Januar 2010 10:49
An: [email protected]
Betreff: Re: st: bottom to top or reverse cumulative distribution in table command?

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

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']"
	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')

sysuse auto, clear
reversecum rep78
*-------------------- end example -----------------------
( For more on how to use examples I sent to statalist see: )

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index