<>
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
*************
HTH
Martin
-----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-
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 )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/
*
* 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/