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

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Adding Reference Bars to Bar Graph |

Date |
Fri, 17 Aug 2012 09:57:47 +0100 |

The only way ahead given that you have taken this road is to add a further category to the data (certainly not a further variable). The following may be suggestive of the main trick involved. I have kept the example as simple as possible. sysuse auto preserve expand 2 in L replace foreign = 2 in L * whatever constant you need replace mpg = 42 in L label def origin 2 "Total" , add graph bar (mean) mpg, over(foreign) restore The problem with -catplot- here that it is based (in your case) on -graph bar-, which does not behave like -twoway- in letting other graphs be superimposed. So you must mess, at least temporarily, with the data. The alternative is to rewrite everything as a call to -twoway bar-, but even in that case the easiest way may be to start with an augmented dataset. Nick On Fri, Aug 17, 2012 at 5:33 AM, William Buchanan <william@williambuchanan.net> wrote: > I'm trying to automate production of a series of bar graphs that show the percentage of values and am having difficulty adding an extra bar with a constant value to the graph. With the exception of this additional bar, I've managed to get something close to the current graphs being used with -catplot- (available from SSC; written by Nick Cox). The syntax that I've used so far (with only slight modification) is: > > catplot schoolyr, over(skills) asyvar recast(bar) blabel(total, format(%2.0f)) percent(schoolyr) bar(1,color(green*.85) lc(black) lw(medthin)) bar(2, color(blue*.325) lc(black) lw(medthin)) ysc(r(0(10)100) lc(black)) ylab(0(10)100, angle(0) glc(black) tlw(vvthin) glw(vvthin)) yti(Percent) legend(label(1 "XXXXX Yr 2 (N=84)") label(2 "XXXXX Yr 3 (N=116)") pos(12) span region(lc(white))) ti("Survey Item Here", color(black)) b1title(" ") graphr(fc(white) color(white) ic(white)) > > > My goal is to get an additional bar added to the graph with values showing the percentage of "overall". In the actual dataset, the "overall" measure is a time-invariant constant and the firm wants to keep the same graphics formatting that they have already used. I've tried messing around with the -over()- options and by adding the additional variable to the -varlist- in the command. In each of these cases, there is a change to the x-axis (instead of showing an additional bar, the bars are disaggregated by the additional variable). I've provided syntax to generate something close to the data that I am working with. The only difference between the syntax above and what I will eventually need to work with is the addition of an -if- statement that will be used to loop over the firms in the dataset. > > Thanks in advance for any assistance, > Billy > > > set obs 200 > set seed 10101 > g schoolyr=2 if _n<=84 > replace schoolyr=3 if schoolyr==. > g sk=runiform() > egen skills=cut(sk), group(4) > sort skills > g overall=1 if _n<=25 > replace overall=2 if _n<=50 & _n>=26 > replace overall=3 if _n<=75 & _n>=51 > replace overall=3 if _n>=76 * * 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: Adding Reference Bars to Bar Graph***From:*William Buchanan <william@williambuchanan.net>

**References**:**Re: st: Common Factor Analysis***From:*Philip Ender <ender97@gmail.com>

**RE: st: Common Factor Analysis***From:*Cameron McIntosh <cnm100@hotmail.com>

**st: Adding Reference Bars to Bar Graph***From:*William Buchanan <william@williambuchanan.net>

- Prev by Date:
**st: coefficient interpretation in OLS** - Next by Date:
**Re: st:combining datasets** - Previous by thread:
**st: Adding Reference Bars to Bar Graph** - Next by thread:
**Re: st: Adding Reference Bars to Bar Graph** - Index(es):