Bar graph with two variables

Hey guys.

So I'm pretty good with the non-graphic part of STATA now, but I fail to understand how to make this specifik bar graph.

What I have, for example, is two variables:

var1 = 3 categories: high, mid, low
var2 = 2 categories: yes, no

What I'd like what to have a bar graph, that would show each of the 3 categories grouped in yes/no, so that I have 6 bars in groups of two, that shows high-yes/no, mid-yes/no, low-yes/no. I get how to make simple bar graphs but I don't get the specifics of bivariate sorting.


Is something like this what you're after?

sysuse auto, clear
tab foreign , gen(for_)

* option 1 - raw counts
graph bar (sum) for_*, over(rep78) legend(order(1 "Domestic" 2 "Foreign"))

* option 2 - proportions
graph bar (mean) for_*, over(rep78) legend(order(1 "Domestic" 2 "Foreign"))

* option 3 - stacked proportions
graph bar (mean) for_*, over(rep78) stack ///
	legend(order(2 "Foreign" 1 "Domestic")) b1title(Repair record 1978) ///
It's somewhat what I'm looking for, but my problem is, that it makes the bars as total of the whole yes/no category and not as three different variables over var1. I'd like to make var2 (yes/no) make two bars pr. var1 category, so that it will be six bars; three "yes" and three "no". One yes and one no for each of the high, mid, low categories. When I, fx, do your first option, I get two bars that show total yes and total no over var1, instead of showing total yes/no in each of var1's categories.


I don't entirely understand what you're trying to do, but it might be as simple as swapping the variables in the example above. I assume you have looked at all of the examples in -help graph bar-

I have often found -graph bar- to be a little counterintuitive, but the examples in the help file usually clarify the syntax needed. You should be experimenting and should be able to figure it out.

If you still can't get it to work I would suggest you show an example of your data structure, and an example of the desired graph similar to the examples in the help file, eg:
            +-+       +-+       +-+
            | |       | |       | |
            | |-+     | |-+     | |-+
            | | |     | | |     | | |
          division  division  division