Exodia16
Exodia16

Reputation: 177

Drawing a complicated bar graph in Stata

I am trying to draw a bar graph with a bar for each separate variable on the y axis and then split them according to a category variable.

So, my variables to put in the x-axis are:

phys
emo
soc
sch

They are all scores from 0 to 100 which show quality of life and I want to split each of these on the x axis by a variable with two categories, either moderate or high. The only thing I can seem to do is:

gr bar phys emo soc sch, over(Village) 

which splits the x axis into Village (either high or moderate) and then splits each of these into 4 categories of phys, emo, soc, sch. Since the four variables are all separate but have the same score, they can't be a category in Stata since it labels the x axis 0-100 which is not what I want.

If anyone can think of a way to help or to combine the four into one variable so that I can use the over(x) option it would be very helpful!

Upvotes: 1

Views: 2318

Answers (1)

SOConnell
SOConnell

Reputation: 793

It looks to me like you have at most 8 data points, in which case I would generally suggest doing a graph like this in MS Excel. However, from your data description, you could do the following:

foreach i in phys emo soc sch {
rename `i' _`i'
}
reshape long _, i(village) j(state) string
g cat=state+"-"+village
gr bar _, over(cat)

Then play with the display options to make the bar labels be smaller & show up nicely, change around colors, etc.

OR

You could do this (without reshaping your data):

graph bar  phys emo soc sch, over(village) bargap(-30) ///
legend( label(1 "Physical") label(2 "Emotional") label(3 "Social") label(4 "School") )

BTW, it's odd to me that you are saying the X-axis is showing up on a 0-100 scale. That shouldn't be happening with this command and if the data are set up the way you are describing. Also that "the variables are separate but have the same score"--really don't know what you're referring to here. Post up your data for better answer....

Here are the fake data I used, which works with my code:

village phys    emo soc sch
high    87  65  79  45
moderate77  64  55  57

Upvotes: 1

Related Questions