[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: creating bar charts
A general rant which applies to many other postings too:
A cardinal principle on Statalist is that most of the so-called
experts are no smarter than you are. They just know more
Stata. Some of us find it too much like hard work to be expected
to upload a lot of information and understand it all instantly. That's why many
of the more detailed posts never get an answer.
First off, you could, and indeed should, short-circuit all the
details about your data by posing a problem everyone can play
The FAQ is explicit:
"If you can, reproduce the error with one of Stata's provided
datasets or a simple concocted dataset that you include in your posting."
Lots of people ignore that, but it's still bad practice to do so.
Second, some of the detail in your graphics command is irrelevant
to the question.
To get anywhere, I fired up the auto dataset and created an
sysuse auto, clear
collapse (mean) mpg, by(foreign rep78)
-note()-, -title()-, -ytitle()- and -bargap()- have no
bearing on your problem. With
graph bar (asis) mpg, over(rep78) over(for)
legend(label(1 "Stars and stripes") label(2 "funny foreign cars"))
I can see what is going on.
The key detail is that what you want to modify is not part of
the legend at all. In fact, I don't think you have a legend.
The stuff you want to modify counts as axis labels. So you
need an analogue of
graph bar (asis) mpg, over(rep78) over(for, relabel(1 "Stars and stripes" 2 "funny foreign cars"))
This is all documented.
The second question is trickier and -- because I want to go home now -- I will
be briefer. In essence, you haven't got an x axis, which sounds like bad news
for the enterprise. One dodge that probably
isn't documented any where is that you can use -b2title()-. There are
other things that could be added here, but that should work.
> I have three variables: sexratio, age and race. Age takes on seven
> different values: 1, 5, 10, 15, 20, 25, and 30. Race takes on two
> value: 1 (white) and 2 (black). Sex ratio is the national ratio of
> on non-incarcerated men to women for each race and each age cohort
> (where "age cohort" refers to five-year gaps in age. So, "5" is 1-5
> year olds, "10" is 6-10, and so on).
> I'm trying to create a simply bar graph, and I've got it working for
> the most part, but I need to change a few things. Here's
> what I have
> so far:
> . graph bar (asis) SexRatio, over(race) over(age) bargap(.80) legend
> ( label(1 "White") label(2 "Black") ) ytitle(Sex Ratio) title(Racial
> Dynamics in the U.S. Sex Ratio) note("Source: 2000 Census longform
> Summary File")
> I thought that by changing the legend labels, it would actually
> report "white" and "black" instead of "1" and "2". But it doesn't.
> I'm not sure what exactly I did, then, by changing the legend
> in this
> way. There's no legend showing up, for instance, to the
> right of the
> graph if it was creating a legend.
> Secondly, I wanted to make an xtitle, showing the reader that
> age was
> along the xaxis in five-year brackets, but when I included an -xtitle
> (Age)- I got an error. Any ideas?
> Secondly, I wanted to make an xtitle, showing the reader that age
> was along the xaxis in five-year brackets, but when I included an -
> xtitle(Age)- I got an error. Any ideas?
For instance, here was my code:
. graph bar (asis) SexRatio, over(race) over(age) bargap(.80) legend
( label(1 "White") label(2 "Black") ) xtitle(Age) ytitle(Sex Ratio)
title(Racial Dynamics in the U.S. Sex Ratio) note("Source: 2000
Census longform Summary File")
yet, I saw in the help for axis titles that xaxis is an option, so
I'm not sure what I did incorrectly here. sc
* For searches and help try: