Data @ Reed

Bar graphs

If you are working with categorical data, bar graphs can provide an accessible summary of your data. Like many commands in Stata, there are a wealth of options for modifying the resulting visuals; for details on myriad possibilities, see the graph bar help documentation. This example will get you started with bar graphs.

Using the wide-format blood pressure data, I'd like to compare blood pressure for patients before and after (some activity - this is a fictitious dataset).

#load the data
sysuse bpwide
#initial graph: bp_before and bp_after
graph bar bp_before bp_after

These dataset-wide means aren't really useful to me as visuals or as numbers. I'd like to break this down a bit

#graph, grouped by sex
graph bar bp_before bp_after, over(sex)
#graph, grouped by agegrp
graph bar bp_before bp_after, over(agegrp)
#graph, grouped by both sex and agegrp
graph bar bp_before bp_after, over(agegrp) over(sex)

Note that the over() command shows data within the same graph. To generate separate graphs for each grouping, use the by() command.

graph bar bp_before bp_after, by(agegrp)

You can combine by() and over(); in this case, I want to visualize patterns within male/female, grouped by age: 

graph bar bp_before bp_after, by(sex) over(agegrp)

The above code should generate a graph something like this:

example_bar_graph

Further documentation:

UCLA Stata page, How do I make a graph with error bars?

For a general introduction to graphics in Stata, see this guide from UCLA.