Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Adding Reference Bars to Bar Graph
William Buchanan <firstname.lastname@example.org>
Re: st: Adding Reference Bars to Bar Graph
Fri, 17 Aug 2012 05:54:34 -0700
I apologize for not clearly explaining things previously (although the solution you suggested would have worked great if I could use it with this problem). I've added an example of what the charts that this company is currently using look like here: https://www.dropbox.com/sh/9g5b6h1ul1ev9br/HTD6u678Er.
I should probably also provide a bit more information about the data itself since that could be helpful. The dataset contains several hundred different firms, each with varying observations per period and varying periods of observation; for example, firm 1 may have only been measured once in 2007 and had 20 observations, but firm 2 may have been measured twice (once in the spring and once in the fall of 2007) and had 13 observations for the first measurement and 40 observations for the second measurement. In the example that I had sent and was working on at first I was ignoring whether the firm was observed more than once in a single year. The "norm avg" is based on a sample of first time observations between 2004-2009 and is fixed for all firms/periods. The thing that is difficult here is that this average is based on values of each of the four categorical values (e.g., there is a norm avg for each of the categories that appears on the chart).
What I'm hoping to achieve for the end goal is a way to consistently and quickly produce the 600+graphs (there are six graphs like this that need to be created for each firm with a different measurement but same scale for each). Given that each firm has a different number of observations per period/year, it would be very difficult to use the expand option (since the percentages for each of the norm averages needs to be the same across all firms).
On Aug 17, 2012, at 1:57 AM, Nick Cox wrote:
> 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
> 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)
> 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.
> On Fri, Aug 17, 2012 at 5:33 AM, William Buchanan
> <email@example.com> 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,
>> 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/
* For searches and help try: