Formatting a Bar Graph

Formatting a Bar Graph

by Emily Hurstak -
Number of replies: 1

The only interesting relationships in my dataset turned out to be between dichotomous variables so I am trying to do a bar graph with several variables to show this (since the scatter/boxplots etc aren't good).  I have a basic bar graph but am having a lot of trouble formatting it correctly so that subheadings and labels are correct and aren't just the variable names (yes/no, or 0/1) .

Here is the command I am working with for your reference.  The Y axis is just the number of people.

graph bar (count) id, over(TBI) over(homeless50) blabel(total) ytitle(Number of respondents) title(TBI in respondents who became homeless before or after the age of 50 yrs.) legend(order (1 "Homeless after 50" 2 "Homeless before 50")).  

My legend doesn't seem to come out correctly.  Do you know the way to code for legend and subheadings OR alternatively -- how do you get the STATA code backwards from changes you made in the graph editor?

 

Thank you!

In reply to Emily Hurstak

Re: Formatting a Bar Graph

by Michael Peters -

Emily,

  The easiest way (I find) to label a graph is to label your variables themselves

For examples with 1/0

I use

label define Gender 1 "Female" 0 "Male"

label values Gender Gender 

The above code for the variable Gender labels all values 1 female and all values 0 value

The next line tells stata that what you labeled as Gender goes with the variable called Gender.  

The same works for "Yes" "No" variables, and you could relabel them "No TBI" "Yes TBI", or whatever you want.

I am not aware of any way to get the actual code, when you use graph editor, a big drawback in my opinion of Stata.

 

MCP