Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: creating bar charts


From   Scott Cunningham <[email protected]>
To   [email protected]
Subject   Re: st: creating bar charts
Date   Fri, 24 Mar 2006 14:06:22 -0500

Tacking this question onto my previous ones - in the help sections, I notice that what I'm attempting to do is done because the variables to be mapped onto the graph are actually different values. For instance, in this code:

. graph bar (mean) tempjuly tempjan, over(region)

This is from the help on -graph bar- from a datafile called - citytemp-. This produces exactly what I'm trying to do, where "region" in my case is "age", and the two variables side by side for each period are the white and black sex ratio. But, my data usually is coded 1 or 2 for race, and not actually separate variables altogether for race. In other words, if I had a variable called "bsr" for black sex ratio and "wsr" for white, then it'd be straightforward to reproduce the above as:

. graph bar (asis) wsr bsr, over(age)

But how do I accomplish the above if I use one variable (called "sexratio") which takes on two values (1 or 2 for white or black), and I wish to graph the white and black sex ratios side by side. When I do this:

. graph bar (asis) SexRatio if race==1 SexRatio if race==2, over(age)

I get an error that says, "invalid 'SexRatio' "

sc


On Mar 24, 2006, at 1:37 PM, Scott Cunningham wrote:


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?


sc
*
* 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/
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index