Docsity

Constructing Bar Charts in Stata: A Step-by-Step Guide, Exercises of Sociology

Toggle sidebar
bg1
!
1!
Revised July 2018!
Bar Charts
This set of notes shows how to construct a bar chart using Stata. It assumes that you
have set Stata up on your computer (see the “Getting Started with Stata” handout),
and that you have read in the set of data that you want to analyze (see the “Reading in
Stata Format (.dta) Data Files” handout).
In Stata, most tasks can be performed either by issuing commands within the “Stata
command” window, or by using the menus. These notes illustrate both approaches,
using the data file “GSS2016.DTA” (this data file is posted here:
https://canvas.harvard.edu/courses/53958).
Bar charts display differences in means for a quantitative variable across two or more
groups, as opposed to histogram comparisons which display percentage distributions
of a categorical variable within groups. For example, we can construct a bar chart of
the mean hours per day of television viewing by self-attributed class:
!
pf3
pf4
pf5

Partial preview of the text

Download Constructing Bar Charts in Stata: A Step-by-Step Guide and more Exercises Sociology in PDF only on Docsity!

Revised July 2018 Bar Charts This set of notes shows how to construct a bar chart using Stata. It assumes that you have set Stata up on your computer (see the “Getting Started with Stata” handout), and that you have read in the set of data that you want to analyze (see the “Reading in Stata Format (.dta) Data Files” handout). In Stata, most tasks can be performed either by issuing commands within the “Stata command” window, or by using the menus. These notes illustrate both approaches, using the data file “GSS2016.DTA” (this data file is posted here: https://canvas.harvard.edu/courses/53958). Bar charts display differences in means for a quantitative variable across two or more groups, as opposed to histogram comparisons which display percentage distributions of a categorical variable within groups. For example, we can construct a bar chart of the mean hours per day of television viewing by self-attributed class:

Simple bar charts can be constructed easily via the Stata command line. The general command structure is graph bar , over() where you enter a quantitative variable in place of “varname1" and a categorical variable in place of “varname2". Using the variables in the above graph, you would issue the command graph bar tvhours, over(class) This command produces a bare-bones graph with no enhancements. To enhance and improve the display, it is probably easier to use the Stata menus. For a bar chart, Click on “Graphics” Click on “Bar chart” When you do this, the “graph bar – Bar chart” window shown below opens up:

To further illustrate the use of these, the same bar chart is shown on the following page, with a title (at top) and a caption (bottom) added, and with a different title for the vertical (Y) axis.

Saving Graphs To save your bar chart(s), see the “Saving Graphs” handout.