Thanks for this. Your specific examples are very welcome.
Your graph can be produced directly by
. sysuse auto, clear
. catplot hbar foreign rep78, percent(foreign) asyvars
I personally would prefer this example from the help
for -tabplot- (SSC)
. tabplot for rep78, percent(foreign) showval(offset(0.05) format(%2.1f))
while there is always something like this:
. histogram rep78, discrete by(foreign) xla(1/5) percent barw(0.6)
Nick
[email protected]
David Radwin
> It turns out the primary limitation I am running up against is not
> related to -catplot- per se but to Stata's graphing capabilities in
> general--or so I think. What I really would like to do is to create
> bar charts where the bars are ordered not by values of the xvar but
> by values of the yvar.
>
> I think this example will make it more clear. Suppose for sake of
> illustration I want to compare the repair records of foreign and
> domestic cars. The commands
>
> sysuse auto, clear
> catplot hbar rep78, over(foreign) percent(foreign)
>
> shows the bars in this order:
>
> 1. percentage of cars with foreign=0 and rep78=1
> 2. percentage of cars with foreign=0 and rep78=2
> . . .
> 6. percentage of cars with foreign=1 and rep78=1 [this bar happens to
> have zero length]
> . . .
> 10. percentage of cars with foreign=1 and rep78=5
>
> That is all well and good, but I want to emphasize the difference
> between foreign and domestic on each value of rep78, with an ordering
> of
>
> 1. percentage of cars with foreign=0 and rep78=1
> 2. percentage of cars with foreign=1 and rep78=1
> 3. percentage of cars with foreign=0 and rep78=2
> 4. percentage of cars with foreign=1 and rep78=2
> . . .
> 9. percentage of cars with foreign=0 and rep78=5
> 10. percentage of cars with foreign=1 and rep78=5
>
> If there is a -graph- option that does this, I would be delighted to
> learn about it. The best I could muster was this workaround:
>
> gen domestic=foreign==0
> collapse (sum) foreign domestic, by(rep78)
> foreach var of varlist foreign domestic {
> egen `var'_tot=total(`var')
> gen `var'_pct=round(100*`var'/`var'_tot , 1)
> }
> graph hbar (asis) domestic_pct foreign_pct , over(rep78)
>
> However, this solution is significantly more cumbersome and less
> flexible than using -catplot-. Can you or anyone else suggest a
> better alternative?
>
> Thanks,
>
> David
>
> At 7:41 PM +0100 7/26/07, n j cox wrote:
> >First, a reminder (to others in this and other threads as well)
> >to say where user-written stuff you cite comes from. -catplot-,
> >in this case, is a program on SSC.
> >
> >Second, what's the implication here? I looked at -catplot-
> >and it allows the user a wildcard to relevant graph options,
> >so you don't lose all control over detail.
> >
> >If you think the program is limited, please make a specific
> >suggestion or criticism, so the author can think about it.
> >
> >The author happens to be me, so I endorse that general
> >principle.
> >
> >Nick
> >[email protected]
> >
> >David Radwin
> >
> >...
> >I would like more examples analogous to -catplot- but
> >with greater control over formatting.
> >....
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/