[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: help in obtaining a bar graph |

Date |
Wed, 13 Aug 2008 17:34:07 +0100 |

First, one rough solution. Then, a few comments. The following is one line. twoway scatteri `=166/528' 1 `=4569/8781' 2 `=362/528' 4 `=4212/8781' 5, recast(bar) barw(0.5) xla(1 "frog" 2 "toad" 4 "newt" 5 "snake" 1.5 `" " " "stuff" "' 4.5 `" " " "nonsense" "', noticks) base(0) xtitle(category) ytitle(fraction) yla(0(0.1)0.7, ang(h)) Advice often given on Statalist is to give up on -graph bar- when it does not offer a solution and to build up your own alternative using -twoway bar-. One of the more puzzling aspects of -graph- initially is that -graph bar- and -twoway bar- can produce quite similar graphs but are nevertheless totally different commands. The trick is not to try to understand this, but just to get used to it. In the above I didn't try a direct attack. I use -twoway scatteri- to say exactly where I want the bars, strictly data points as yet. Macro-like elements like `=166/528' instruct Stata to work out cell fractions on the fly. Then I -recast()- to bars. The rest is standard -twoway- technique. I have not tried to work out from Rich's colourless terminology -- perhaps protecting a client! -- what the best axis labels and titles should be but used filler terms. There is enormous scope for tuning all the cosmetic aspects. No doubt this could be automated more. Nick n.j.cox@durham.ac.uk Richard Goldstein I have two variables defined as shown in the following table: | event type1 | N Y | Total -----------+----------------------+---------- N | 4,403 166 | 4,569 | 53.35 31.44 | 52.03 -----------+----------------------+---------- Y | 3,850 362 | 4,212 | 46.65 68.56 | 47.97 -----------+----------------------+---------- Total | 8,253 528 | 8,781 | 100.00 100.00 | 100.00 I want a bar graph showing 4 bars as follows: 166/528 and 4569/8781 362/528 and 4212/8781 I.e., I want the Y and Total columns rather than the N and Y columns. I have no idea how to get this and any help/ideas would be greatly appreciated. Note that I can live with having 6 bars (2 for the N column in addition) if I have to. * * 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: RE: help in obtaining a bar graph***From:*Richard Goldstein <richgold@ix.netcom.com>

**References**:**st: help in obtaining a bar graph***From:*Richard Goldstein <richgold@ix.netcom.com>

- Prev by Date:
**RE: st: number format in graph labels** - Next by Date:
**Re: st: Testing for serial correlation in residuals under panel data** - Previous by thread:
**st: help in obtaining a bar graph** - Next by thread:
**Re: st: RE: help in obtaining a bar graph** - Index(es):

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