Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • showing cumulative proportion on histogram

    I have variable called rx_day which takes values rom 0 to 90 days. I want to plot a histogram to show the distribution of values. I used this command

    histogram rx_day, percent fcolor(dknavy)
    (bin=52, start=0, width=1.7307692)

    how can I show the cumulative proportion from 0-30 , 0-60, 0-90 , as described in the fourth column when I use the tab command ??

    rx_day | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 5,433 3.16 3.16
    1 | 9,832 5.72 8.88
    2 | 9,499 5.53 14.41
    3 | 10,316 6.00 20.41
    4 | 10,921 6.35 26.76
    5 | 9,533 5.55 32.31
    6 | 8,792 5.12 37.43
    7 | 9,066 5.27 42.70
    8 | 6,124 3.56 46.26
    9 | 4,979 2.90 49.16
    10 | 4,909 2.86 52.02

  • #2
    This seems to be what you are asking for, but for 90 or so bins the results will be underwhelming as bins average about 1% each and will be swamped by the cumulative.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    
    * this is for other people 
    clear 
    input float rx_day int _freq
     0  5433
     1  9832
     2  9499
     3 10316
     4 10921
     5  9533
     6  8792
     7  9066
     8  6124
     9  4979
    10  4909
    end
    
    * Reema starts here; take the comment flag off the next command 
    * save dataset carefully first 
    * contract rx_day 
    
    cumul rx_day [fw=_freq], gen(cdf) 
    replace cdf = cdf * 100 
    
    gen x = rx_day - 0.5 
    insobs 1 
    su rx_day, meanonly 
    replace x = r(max) + 0.5 in L 
    replace cdf = cdf[_n-1] in L 
    
    local yla 0(25)100 
    set scheme s1color 
    histogram rx_day [fw=_freq] , percent yla(`yla', ang(h)) discrete fcolor(blue*0.4) lcolor(blue) width(1) addplot(line cdf x, c(J) lw(medthick)) legend(off) ytitle(percent and cumulative)
    Click image for larger version

Name:	hist_cumul.png
Views:	1
Size:	13.4 KB
ID:	1688253

    Comment

    Working...
    X