Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Austin Nichols <austinnichols@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Stacked bar graph with twoway__histogram_gen |

Date |
Wed, 7 Mar 2012 13:38:07 -0500 |

Stefano Lombardi <lombardi_stefano@fastwebnet.it>: At a glance, your -rbar- goes from freq_2 to the sum, not freq_1 to the sum. On Wed, Mar 7, 2012 at 1:28 PM, Stefano Lombardi <lombardi_stefano@fastwebnet.it> wrote: > Dear Statalisters, > > I have a problem in plotting a stacked bar graph. I have read some > documentation on the Internet and I am really close to obtain what I need, > but still I cannot manage to solve one issue (I haven't found any similar > problem on the Statalist archive..) > > In practice, I have one duration variable in months (overall survival, "os") > which as usual can be either censored or uncensored (the failure dummy is > "status_os"; 1 = os is uncensored). I need to create a stacked bar graph > with different colors for censored and uncensored data (blue and red, > respectively). My code is the following: > > use "epd0", clear > twoway__histogram_gen os if status_os==0, gen(freq_1 x, replace) /// > freq start(0) width(5) > drop if missing(x) > keep freq_1 x > save f1, replace > > use "epd0", clear > twoway__histogram_gen os if status_os==1, gen(freq_2 x, replace) /// > freq start(0) width(5) > drop if missing(x) > keep freq_2 x os > > merge 1:1 x using f1 > mvencode freq_1 freq_2, mv(. = 0) > > egen freq = rowtotal(freq_1 freq_2) > > twoway /// > (bar freq_1 x, barw(5) bcolor(red)) /// > rbar freq_2 freq x, barw(5) bcolor(blue) /// > legend(order(1 "Uncensored" 2 "Censored")) /// > xtitle("`: var label os'") ytitle(Frequency) > > Everything looks perfect but for one thing. In one bin there is a blank gap > between the lower red bar (which counts for two observations) and the upper > blue bar (other two observations). > Actually -- also by checking the previously generated frequencies -- the > lower bar should correspond to three observations, hence the blank gap > should be red. > > Can you suggest any solution? It may be a coincidence, but that bin is the > only one where there should be plotted more uncensored (red) data than > censored (blue) ones. * * 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/

**Follow-Ups**:**Re: st: Stacked bar graph with twoway__histogram_gen***From:*Austin Nichols <austinnichols@gmail.com>

**References**:**st: Stacked bar graph with twoway__histogram_gen***From:*Stefano Lombardi <lombardi_stefano@fastwebnet.it>

- Prev by Date:
**Re: st: RE: Figure out in which do-file an error occurred** - Next by Date:
**Re: st: Looping over variables in more than one group** - Previous by thread:
**st: Stacked bar graph with twoway__histogram_gen** - Next by thread:
**Re: st: Stacked bar graph with twoway__histogram_gen** - Index(es):