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

st: RE: Cumulative Distribution


From   "Jann Ben" <[email protected]>
To   <[email protected]>
Subject   st: RE: Cumulative Distribution
Date   Wed, 28 Sep 2005 12:20:23 +0200

A day ago or two, Ronnie Babigumira wrote:

> I have a data that looks something like this
> par_id	ag_area
> 1	112.2
> 2	91.3
> 3	74.7
> 4	64.3
> 5	57.3
> 6	42.4
> 7	75.4
> 8	77.7
> 9	102.9
> 10	108.0
> 
> Where par_id is the parish id (an adminstrative unit), and ag_area, is
> the agricultural area in a given parish
> 
> I would like to plot a cumulative distribution of the ag_area. I would
> like a plot that would look something like
> 
> ag_area(%)
> 100       * * *
> |      *
> |    *
> |  *
> |*
> |_ _ _ _ _ _ _ __ (number of parishes %)
>                   100

My answer was:

> How about
> 
>  . cumul par_id [aw=ag_area], generate(c)
>  . scatter c par_id, ylabel(0(.1)1)

But this was not quite it. Meanwhile, Ronnie contacted
me offlist. It turned out that he wanted to plot the 
cumulative distribution of ag_area ordered by decreasing 
values of ag_area. Thus, the solution is: 

 . gen df = ag_area
 . sum df, meanonly
 . local sum = r(sum)
 . gsort -df                          // reverse order
 . replace df = sum(df) / `sum' * 100 // cumulative area
 . gen pc = _n/_N * 100               // proportion of cells
 . scatter df pc, ylabel(0(10)100) xlabel(0(10)100)

ben

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