SlideShare a Scribd company logo
Stata Graphics

Harvard MIT Data Center

The Institute

for Quantitative Social Science
at Harvard University

(Harvard MIT Data Center)

Stata Graphics

1 / 38
Outline

1

Introduction

2

Univariate Graphics

3

Bivariate Graphics

4

More Fun with Twoway Line Graphs

5

Wrap-up

(Harvard MIT Data Center)

Stata Graphics

2 / 38
Introduction

Topic

1

Introduction

2

Univariate Graphics

3

Bivariate Graphics

4

More Fun with Twoway Line Graphs

5

Wrap-up

(Harvard MIT Data Center)

Stata Graphics

3 / 38
Introduction

Documents for today

USERNAME: dataclass PASSWORD: dataclass
Find class materials at: Scratch > StataStatistics
FIRST THING: copy this folder to your desktop!

(Harvard MIT Data Center)

Stata Graphics

4 / 38
Introduction

Organization

Please feel free to ask questions at any point if they are relevant to the
current topic (or if you are lost!)
There will be a Q&A after class for more specific, personalized questions
Collaboration with your neighbors is encouraged
If you are using a laptop, you will need to adjust paths accordingly
Make comments in your Do-file rather than on hand-outs
Save on flash drive or email to yourself

(Harvard MIT Data Center)

Stata Graphics

5 / 38
Introduction

Graphing Strategies
Keep it simple
Labels, labels, labels!!
Avoid cluttered graphs
Every part of the graph should be meaningful
Avoid:
Shading
Distracting colors
Decoration

Always know what you’re working with before you get started
Recognize scale of data
If you’re using multiple variables – how do their scales align?

Before any graphing procedure review variables with codebook, sum,
tab, etc.
HELPFUL STATA HINT: If you want your command to go on multiple
lines use /// at end of each line
(Harvard MIT Data Center)

Stata Graphics

6 / 38
Introduction

Terrible Graph

(Harvard MIT Data Center)

Stata Graphics

7 / 38
Introduction

Much Better Graph

(Harvard MIT Data Center)

Stata Graphics

8 / 38
Univariate Graphics

Topic

1

Introduction

2

Univariate Graphics

3

Bivariate Graphics

4

More Fun with Twoway Line Graphs

5

Wrap-up

(Harvard MIT Data Center)

Stata Graphics

9 / 38
Univariate Graphics

Our First Dataset

Time Magazine Public School Poll
Based on survey of 1,000 adults in U.S.
Conducted in August 2010
Questions regarding feelings about parental involvement, teachers union,
current potential for reform

Open Stata and call up the datafile for today
// Step 1: tell Stata where to find data:
cd /Users/dataclass/Desktop/StataGraphics/dataSets
// Step 2: call up our dataset:
use TimePollPubSchools.dta

(Harvard MIT Data Center)

Stata Graphics

10 / 38
Univariate Graphics

Single Continuous Variables

Example: Histograms
Stata assumes you’re working with continuous data
Very simple syntax:
hist varname

Put a comma after your varname and start adding options
bin(#) : change the number of bars that the graph displays
normal : overlay normal curve
addlabels : add actual values to bars

(Harvard MIT Data Center)

Stata Graphics

11 / 38
Univariate Graphics

Histogram Options

To change the numeric depiction of your data add these options after
the comma
Choose one: density fraction frequency percent

Be sure to properly describe your histogram:
title(insert name of graph)
subtitle(insert subtitle of graph)
note(insert note to appear at bottom of graph)
caption(insert caption to appear below notes)

(Harvard MIT Data Center)

Stata Graphics

12 / 38
Univariate Graphics

Histogram Example
hist F1, bin(10) percent title(TITLE) ///
subtitle(SUBTITLE) caption(CAPTION) note(NOTES)

(Harvard MIT Data Center)

Stata Graphics

13 / 38
Univariate Graphics

Axis Titles and Labels
Example: Histograms
Axis title options (default is variable label):
xtitle(insert x axis name)
ytitle(insert y axis name)

Don’t want axis titles?
xtitle("")
ytitle("")

Add labels to X or Y axis:
xlabel(insert x axis label)
ylabel(insert y axis label)

Tell Stata how to scale each axis
xlabel(start#(increment)end#)
xlabel(0(5)100)

This would label x-axis from 0-100 in increments of 5

(Harvard MIT Data Center)

Stata Graphics

14 / 38
Univariate Graphics

Axis Labels Example
hist F1, bin(10) percent title(TITLE) subtitle(SUBTITLE) ///
caption(CAPTION) note(NOTES) ///
xtitle(Here ’ s your x-axis title) ///
ytitle(here ’ s your y-axis title)

(Harvard MIT Data Center)

Stata Graphics

15 / 38
Univariate Graphics

Basic Graphing: Single Categorical Variables
We can also use the hist command for bar graphs
Simply specify "discrete" with options

Stata will produce one bar for each level (i.e. category) of variable
Use xlabel command to insert names of individual categories
hist F4, title(Racial breakdown of Time Poll Sample) xtitle(Race) ///
ytitle(Percent) xlabel(1 "White" 2 "Black" 3 "Asian" 4 "Hispanic" ///
5 "Other") discrete percent addlabels

(Harvard MIT Data Center)

Stata Graphics

16 / 38
Univariate Graphics

Exercise 1: Histograms Bar Graphs
1

Open the datafile, NatNeighCrimeStudy.dta.

2

Create a histogram of the tract-level poverty rate (variable name:
T_POVRTY).

3

Insert the normal curve over the histogram

4

Change the numeric representation on the Y-axis to "percent"

5

Add appropriate titles to the overall graph and the x axis and y axis.
Also, add a note that states the source of this data.

6

Open the datafile, TimePollPubSchools.dta

7

Create a histogram of the question, "What grade would you give your
child’s school" (variable name: Q11). Be sure to tell Stata that this is a
categorical variable.

8

Format this graph so that the axes have proper titles and labels. Also,
add an appropriate title to the overall graph that goes onto two lines.
Add a note stating the source of the data.

(Harvard MIT Data Center)

Stata Graphics

17 / 38
Univariate Graphics

Next Dataset:

National Neighborhood Crime Study (NNCS)
N=9,593 census tracts in 2000
Explore sources of variation in crime for communities in the United States
Tract-level data: crime, social disorganization, disadvantage,
socioeconomic inequality
City-level data: labor market, socioeconomic inequality, population
change

(Harvard MIT Data Center)

Stata Graphics

18 / 38
Bivariate Graphics

Topic

1

Introduction

2

Univariate Graphics

3

Bivariate Graphics

4

More Fun with Twoway Line Graphs

5

Wrap-up

(Harvard MIT Data Center)

Stata Graphics

19 / 38
Bivariate Graphics

The Twoway Family

twoway is basic Stata command for all twoway graphs
Use twoway anytime you want to make comparisons among variables
Can be used to combine graphs (i.e., overlay one graph with another
e.g., insert line of best fit over a scatter plot

Some basic examples:
use NatNeighCrimeStudy.dta
tw scatter T_PERCAP T_VIOLNT
tw dropline T_PERCAP T_VIOLNT
tw lfitci T_PERCAP T_VIOLNT

(Harvard MIT Data Center)

Stata Graphics

20 / 38
Bivariate Graphics

Twoway and the "by" Statement
twoway scatter T_PERCAP T_VIOLNT, by(DIVISION)

(Harvard MIT Data Center)

Stata Graphics

21 / 38
Bivariate Graphics

Twoway Title Options

Same title options as with histogram
title(insert name of graph)
subtitle(insert subtitle of graph)
note(insert note to appear at bottom of graph)
caption(insert caption to appear below notes)

(Harvard MIT Data Center)

Stata Graphics

22 / 38
Bivariate Graphics

Twoway Title Options Example

twoway scatter T_PERCAP T_VIOLNT, ///
title(Comparison of Per Capita Income ///
and Violent Crime Rate at Tract level) ///
xtitle(Violent Crime Rate) ytitle(Per Capita Income) ///
note(Source: National Neighborhood Crime Study 2000)

The title is a bit cramped–let’s fix that:
twoway scatter T_PERCAP T_VIOLNT, ///
title("Comparison of Per Capita Income" ///
"and Violent Crime Rate at Tract level") ///
xtitle(Violent Crime Rate) ytitle(Per Capita Income) ///
note(Source: National Neighborhood Crime Study 2000)

(Harvard MIT Data Center)

Stata Graphics

23 / 38
Bivariate Graphics

Twoway Symbol Options
A variety of symbol shapes are available: use palette symbolpalette
to seem them and msymbol() to set them

(Harvard MIT Data Center)

Stata Graphics

24 / 38
Bivariate Graphics

Twoway Symbol Options
twoway scatter T_PERCAP T_VIOLNT, ///
title("Comparison of Per Capita Income" ///
"and Violent Crime Rate at Tract level") ///
xtitle(Violent Crime Rate) ytitle(Per Capita Income) ///
note(Source: National Neighborhood Crime Study 2000) ///
msymbol(Sh) mcolor("red")

(Harvard MIT Data Center)

Stata Graphics

25 / 38
Bivariate Graphics

Overlaying Twoway Graphs

Very simple to combine multiple graphs. . . just put each graph command
in parentheses
twoway (scatter var1 var2) (lfit var1 var2)

Add individual options to each graph within the parentheses
Add overall graph options as usual following the comma
twoway (scatter var1 var2) (lfit var1 var2), options

(Harvard MIT Data Center)

Stata Graphics

26 / 38
Bivariate Graphics

Overlaying Points and Lines

twoway (scatter T_PERCAP T_VIOLNT) ///
(lfit T_PERCAP T_VIOLNT), ///
title("Comparison of Per Capita Income" ///
"and Violent Crime Rate at Tract level") ///
xtitle(Violent Crime Rate) ytitle(Per Capita Income) ///
note(Source: National Neighborhood Crime Study 2000)

(Harvard MIT Data Center)

Stata Graphics

27 / 38
Bivariate Graphics

Overlaying Points and Labels

twoway (scatter T_PERCAP T_VIOLNT if T_VIOLNT==1976, ///
mlabel(CITY)) (scatter T_PERCAP T_VIOLNT), ///
title("Comparison of Per Capita Income" ///
"and Violent Crime Rate at Tract level") ///
xlabel(0(200)2400) note(Source: National Neighborhood ///
Crime Study 2000) legend(off)

(Harvard MIT Data Center)

Stata Graphics

28 / 38
Bivariate Graphics

Exercise 2: The TwoWay Family
Open the datafile, NatNeighCrimeStudy.dta.
1

Create a basic twoway scatterplot that compares the city unemployment
rate (C_UNEMP) to the percent secondary sector low-wage jobs
(C_SSLOW)

2

Generate the same scatterplot, but this time, divide the plot by the
dummy variable indicating whether the city is located in the south or not
(C_SOUTH)

3

Change the color of the symbol that you use in this scatter plot

4

Change the type of symbol you use to a marker of your choice

5

Notice in your scatterplot that is broken down by C_SOUTH that there is
an outlier in the upper right hand corner of the "Not South" graph. Add
the city name label to this marker.

6

Review the options available under "help twowayoptions " and change one
aspect of your graph using an option that we haven’t already reviewed

(Harvard MIT Data Center)

Stata Graphics

29 / 38
More Fun with Twoway Line Graphs

Topic

1

Introduction

2

Univariate Graphics

3

Bivariate Graphics

4

More Fun with Twoway Line Graphs

5

Wrap-up

(Harvard MIT Data Center)

Stata Graphics

30 / 38
More Fun with Twoway Line Graphs

Line Graphs

Line graphs helpful for a variety of data
Especially any type of time series data

We’ll use data on US life expectancy from 1900-1999
webuse uslifeexp, clear

(Harvard MIT Data Center)

Stata Graphics

31 / 38
More Fun with Twoway Line Graphs

Line Graphs
webuse uslifeexp, clear
twoway (line le_wm year, mcolor("red")) ///
(line le_bm year, mcolor("green"))

(Harvard MIT Data Center)

Stata Graphics

32 / 38
More Fun with Twoway Line Graphs

Line Graphs
twoway (line (le_wfemale le_wmale le_bf le_bm) year, ///
lpattern(dot solid dot solid))

(Harvard MIT Data Center)

Stata Graphics

33 / 38
More Fun with Twoway Line Graphs

Stata Graphing Lines
palette linepalette

(Harvard MIT Data Center)

Stata Graphics

34 / 38
More Fun with Twoway Line Graphs

Exporting Graphs

From Stata, right click on image and select "save as" or try syntax:
graph export myfig.esp, replace

In Microsoft Word: insert > picture > from file
Or, right click on graph in Stata and copy and paste into Word

(Harvard MIT Data Center)

Stata Graphics

35 / 38
Wrap-up

Topic

1

Introduction

2

Univariate Graphics

3

Bivariate Graphics

4

More Fun with Twoway Line Graphs

5

Wrap-up

(Harvard MIT Data Center)

Stata Graphics

36 / 38
Wrap-up

Help Us Make This Workshop Better

Please take a moment to fill out a very short feedback form
These workshops exist for you–tell us what you need!
http://tinyurl.com/StataGraphicsFeedback

(Harvard MIT Data Center)

Stata Graphics

37 / 38
Wrap-up

Additional resources

training and consulting
IQSS workshops:
http://projects.iq.harvard.edu/rtc/filter_by/workshops
IQSS statistical consulting: http://rtc.iq.harvard.edu

Stata resources
UCLA website: http://www.ats.ucla.edu/stat/Stata/
Great for self-study
Links to resources

Stata website: http://www.stata.com/help.cgi?contents
Email list: http://www.stata.com/statalist/

(Harvard MIT Data Center)

Stata Graphics

38 / 38

More Related Content

PPTX
Logistic regression
PPT
PPTX
Missing Data and data imputation techniques
PPTX
R programming
PPTX
Statistics vs machine learning
PPTX
Hierarchical clustering
PPT
Multinomial logisticregression basicrelationships
PDF
Logistic Regression Analysis
Logistic regression
Missing Data and data imputation techniques
R programming
Statistics vs machine learning
Hierarchical clustering
Multinomial logisticregression basicrelationships
Logistic Regression Analysis

What's hot (20)

PDF
Linear regression without tears
DOCX
Binary Logistic Regression
PPTX
Logistic regression
PPTX
How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
PPTX
Module 2_ Regression Models..pptx
PDF
Data Science - Part IV - Regression Analysis & ANOVA
PDF
Big data unit i
PPTX
PDF
Introduction to R and R Studio
PPTX
Generalized linear model
PPTX
Cluster analysis
PDF
Statistics For Data Science | Statistics Using R Programming Language | Hypot...
PPTX
Different kind of distance and Statistical Distance
PPTX
Introduction to Linear Discriminant Analysis
PDF
Introduction to Rstudio
PPTX
Multivariate analysis
PDF
Introduction to R
PPTX
TIME SERIES ANALYSIS.pptx
PDF
Multivariate Analysis
PPTX
Statistics report THE RANGE
Linear regression without tears
Binary Logistic Regression
Logistic regression
How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
Module 2_ Regression Models..pptx
Data Science - Part IV - Regression Analysis & ANOVA
Big data unit i
Introduction to R and R Studio
Generalized linear model
Cluster analysis
Statistics For Data Science | Statistics Using R Programming Language | Hypot...
Different kind of distance and Statistical Distance
Introduction to Linear Discriminant Analysis
Introduction to Rstudio
Multivariate analysis
Introduction to R
TIME SERIES ANALYSIS.pptx
Multivariate Analysis
Statistics report THE RANGE
Ad

Viewers also liked (15)

PPTX
STATA - Graphing Data
PPT
Model probit
PPT
Logical Framework And Project Proposal
PDF
Data management in Stata
PPTX
Probit analysis in toxicological studies
PPTX
Probit analysis
PPTX
STATA - Probit Analysis
PPTX
Probit and logit model
PPTX
STATA - Panel Regressions
PPTX
STATA - Download Examples
PPTX
STATA - Introduction
PPTX
STATA - Time Series Analysis
PPT
Monitoring and Evaluation Framework
PPT
Project Monitoring & Evaluation
PPT
Monitoring & evaluation presentation[1]
STATA - Graphing Data
Model probit
Logical Framework And Project Proposal
Data management in Stata
Probit analysis in toxicological studies
Probit analysis
STATA - Probit Analysis
Probit and logit model
STATA - Panel Regressions
STATA - Download Examples
STATA - Introduction
STATA - Time Series Analysis
Monitoring and Evaluation Framework
Project Monitoring & Evaluation
Monitoring & evaluation presentation[1]
Ad

Similar to Graphing stata (2 hour course) (20)

DOCX
Stata claass lecture
PPTX
Statistics Linear Regression Model by Maqsood Asalam
PPTX
Complete_STATA_Introduction_Beginner.pptx
PPTX
Introduction - Using Stata
PDF
Phd courselez1introtostata
PPTX
Introduction
PDF
Introduction to STATA(2).pdf
PDF
Getting started with stata 13
PPTX
Time Series.pptx
PPT
Introduction to Stata
PPTX
introduction-stata.pptx
PPTX
introductions to Stata software power point
PDF
10 Essential Descriptive Statistics Commands in STATA Assignments.pdf
PDF
the didactic material of Statistics II .pdf
PPTX
Day-2.pptx
PPTX
PPTX
Exploratory Spatial Data Analysis spatial data analysis and interpretation.pptx
DOCX
Lab 3 Set Working Directory, Scatterplots and Introduction to.docx
PDF
Categorical data stata cox 2004
DOCX
UNIT-4.docx
Stata claass lecture
Statistics Linear Regression Model by Maqsood Asalam
Complete_STATA_Introduction_Beginner.pptx
Introduction - Using Stata
Phd courselez1introtostata
Introduction
Introduction to STATA(2).pdf
Getting started with stata 13
Time Series.pptx
Introduction to Stata
introduction-stata.pptx
introductions to Stata software power point
10 Essential Descriptive Statistics Commands in STATA Assignments.pdf
the didactic material of Statistics II .pdf
Day-2.pptx
Exploratory Spatial Data Analysis spatial data analysis and interpretation.pptx
Lab 3 Set Working Directory, Scatterplots and Introduction to.docx
Categorical data stata cox 2004
UNIT-4.docx

More from izahn (8)

PDF
Introduction to SAS
PDF
Stata datman
PDF
Introduction to Stata
PDF
Stata statistics
PDF
Introduction to R Programming
PDF
Introduction to R Graphics with ggplot2
PDF
R Regression Models with Zelig
PDF
Introduction to the R Statistical Computing Environment
Introduction to SAS
Stata datman
Introduction to Stata
Stata statistics
Introduction to R Programming
Introduction to R Graphics with ggplot2
R Regression Models with Zelig
Introduction to the R Statistical Computing Environment

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Institutional Correction lecture only . . .
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
human mycosis Human fungal infections are called human mycosis..pptx
Microbial disease of the cardiovascular and lymphatic systems
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz
Institutional Correction lecture only . . .
Pharma ospi slides which help in ospi learning
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Graphing stata (2 hour course)

  • 1. Stata Graphics Harvard MIT Data Center The Institute for Quantitative Social Science at Harvard University (Harvard MIT Data Center) Stata Graphics 1 / 38
  • 2. Outline 1 Introduction 2 Univariate Graphics 3 Bivariate Graphics 4 More Fun with Twoway Line Graphs 5 Wrap-up (Harvard MIT Data Center) Stata Graphics 2 / 38
  • 3. Introduction Topic 1 Introduction 2 Univariate Graphics 3 Bivariate Graphics 4 More Fun with Twoway Line Graphs 5 Wrap-up (Harvard MIT Data Center) Stata Graphics 3 / 38
  • 4. Introduction Documents for today USERNAME: dataclass PASSWORD: dataclass Find class materials at: Scratch > StataStatistics FIRST THING: copy this folder to your desktop! (Harvard MIT Data Center) Stata Graphics 4 / 38
  • 5. Introduction Organization Please feel free to ask questions at any point if they are relevant to the current topic (or if you are lost!) There will be a Q&A after class for more specific, personalized questions Collaboration with your neighbors is encouraged If you are using a laptop, you will need to adjust paths accordingly Make comments in your Do-file rather than on hand-outs Save on flash drive or email to yourself (Harvard MIT Data Center) Stata Graphics 5 / 38
  • 6. Introduction Graphing Strategies Keep it simple Labels, labels, labels!! Avoid cluttered graphs Every part of the graph should be meaningful Avoid: Shading Distracting colors Decoration Always know what you’re working with before you get started Recognize scale of data If you’re using multiple variables – how do their scales align? Before any graphing procedure review variables with codebook, sum, tab, etc. HELPFUL STATA HINT: If you want your command to go on multiple lines use /// at end of each line (Harvard MIT Data Center) Stata Graphics 6 / 38
  • 7. Introduction Terrible Graph (Harvard MIT Data Center) Stata Graphics 7 / 38
  • 8. Introduction Much Better Graph (Harvard MIT Data Center) Stata Graphics 8 / 38
  • 9. Univariate Graphics Topic 1 Introduction 2 Univariate Graphics 3 Bivariate Graphics 4 More Fun with Twoway Line Graphs 5 Wrap-up (Harvard MIT Data Center) Stata Graphics 9 / 38
  • 10. Univariate Graphics Our First Dataset Time Magazine Public School Poll Based on survey of 1,000 adults in U.S. Conducted in August 2010 Questions regarding feelings about parental involvement, teachers union, current potential for reform Open Stata and call up the datafile for today // Step 1: tell Stata where to find data: cd /Users/dataclass/Desktop/StataGraphics/dataSets // Step 2: call up our dataset: use TimePollPubSchools.dta (Harvard MIT Data Center) Stata Graphics 10 / 38
  • 11. Univariate Graphics Single Continuous Variables Example: Histograms Stata assumes you’re working with continuous data Very simple syntax: hist varname Put a comma after your varname and start adding options bin(#) : change the number of bars that the graph displays normal : overlay normal curve addlabels : add actual values to bars (Harvard MIT Data Center) Stata Graphics 11 / 38
  • 12. Univariate Graphics Histogram Options To change the numeric depiction of your data add these options after the comma Choose one: density fraction frequency percent Be sure to properly describe your histogram: title(insert name of graph) subtitle(insert subtitle of graph) note(insert note to appear at bottom of graph) caption(insert caption to appear below notes) (Harvard MIT Data Center) Stata Graphics 12 / 38
  • 13. Univariate Graphics Histogram Example hist F1, bin(10) percent title(TITLE) /// subtitle(SUBTITLE) caption(CAPTION) note(NOTES) (Harvard MIT Data Center) Stata Graphics 13 / 38
  • 14. Univariate Graphics Axis Titles and Labels Example: Histograms Axis title options (default is variable label): xtitle(insert x axis name) ytitle(insert y axis name) Don’t want axis titles? xtitle("") ytitle("") Add labels to X or Y axis: xlabel(insert x axis label) ylabel(insert y axis label) Tell Stata how to scale each axis xlabel(start#(increment)end#) xlabel(0(5)100) This would label x-axis from 0-100 in increments of 5 (Harvard MIT Data Center) Stata Graphics 14 / 38
  • 15. Univariate Graphics Axis Labels Example hist F1, bin(10) percent title(TITLE) subtitle(SUBTITLE) /// caption(CAPTION) note(NOTES) /// xtitle(Here ’ s your x-axis title) /// ytitle(here ’ s your y-axis title) (Harvard MIT Data Center) Stata Graphics 15 / 38
  • 16. Univariate Graphics Basic Graphing: Single Categorical Variables We can also use the hist command for bar graphs Simply specify "discrete" with options Stata will produce one bar for each level (i.e. category) of variable Use xlabel command to insert names of individual categories hist F4, title(Racial breakdown of Time Poll Sample) xtitle(Race) /// ytitle(Percent) xlabel(1 "White" 2 "Black" 3 "Asian" 4 "Hispanic" /// 5 "Other") discrete percent addlabels (Harvard MIT Data Center) Stata Graphics 16 / 38
  • 17. Univariate Graphics Exercise 1: Histograms Bar Graphs 1 Open the datafile, NatNeighCrimeStudy.dta. 2 Create a histogram of the tract-level poverty rate (variable name: T_POVRTY). 3 Insert the normal curve over the histogram 4 Change the numeric representation on the Y-axis to "percent" 5 Add appropriate titles to the overall graph and the x axis and y axis. Also, add a note that states the source of this data. 6 Open the datafile, TimePollPubSchools.dta 7 Create a histogram of the question, "What grade would you give your child’s school" (variable name: Q11). Be sure to tell Stata that this is a categorical variable. 8 Format this graph so that the axes have proper titles and labels. Also, add an appropriate title to the overall graph that goes onto two lines. Add a note stating the source of the data. (Harvard MIT Data Center) Stata Graphics 17 / 38
  • 18. Univariate Graphics Next Dataset: National Neighborhood Crime Study (NNCS) N=9,593 census tracts in 2000 Explore sources of variation in crime for communities in the United States Tract-level data: crime, social disorganization, disadvantage, socioeconomic inequality City-level data: labor market, socioeconomic inequality, population change (Harvard MIT Data Center) Stata Graphics 18 / 38
  • 19. Bivariate Graphics Topic 1 Introduction 2 Univariate Graphics 3 Bivariate Graphics 4 More Fun with Twoway Line Graphs 5 Wrap-up (Harvard MIT Data Center) Stata Graphics 19 / 38
  • 20. Bivariate Graphics The Twoway Family twoway is basic Stata command for all twoway graphs Use twoway anytime you want to make comparisons among variables Can be used to combine graphs (i.e., overlay one graph with another e.g., insert line of best fit over a scatter plot Some basic examples: use NatNeighCrimeStudy.dta tw scatter T_PERCAP T_VIOLNT tw dropline T_PERCAP T_VIOLNT tw lfitci T_PERCAP T_VIOLNT (Harvard MIT Data Center) Stata Graphics 20 / 38
  • 21. Bivariate Graphics Twoway and the "by" Statement twoway scatter T_PERCAP T_VIOLNT, by(DIVISION) (Harvard MIT Data Center) Stata Graphics 21 / 38
  • 22. Bivariate Graphics Twoway Title Options Same title options as with histogram title(insert name of graph) subtitle(insert subtitle of graph) note(insert note to appear at bottom of graph) caption(insert caption to appear below notes) (Harvard MIT Data Center) Stata Graphics 22 / 38
  • 23. Bivariate Graphics Twoway Title Options Example twoway scatter T_PERCAP T_VIOLNT, /// title(Comparison of Per Capita Income /// and Violent Crime Rate at Tract level) /// xtitle(Violent Crime Rate) ytitle(Per Capita Income) /// note(Source: National Neighborhood Crime Study 2000) The title is a bit cramped–let’s fix that: twoway scatter T_PERCAP T_VIOLNT, /// title("Comparison of Per Capita Income" /// "and Violent Crime Rate at Tract level") /// xtitle(Violent Crime Rate) ytitle(Per Capita Income) /// note(Source: National Neighborhood Crime Study 2000) (Harvard MIT Data Center) Stata Graphics 23 / 38
  • 24. Bivariate Graphics Twoway Symbol Options A variety of symbol shapes are available: use palette symbolpalette to seem them and msymbol() to set them (Harvard MIT Data Center) Stata Graphics 24 / 38
  • 25. Bivariate Graphics Twoway Symbol Options twoway scatter T_PERCAP T_VIOLNT, /// title("Comparison of Per Capita Income" /// "and Violent Crime Rate at Tract level") /// xtitle(Violent Crime Rate) ytitle(Per Capita Income) /// note(Source: National Neighborhood Crime Study 2000) /// msymbol(Sh) mcolor("red") (Harvard MIT Data Center) Stata Graphics 25 / 38
  • 26. Bivariate Graphics Overlaying Twoway Graphs Very simple to combine multiple graphs. . . just put each graph command in parentheses twoway (scatter var1 var2) (lfit var1 var2) Add individual options to each graph within the parentheses Add overall graph options as usual following the comma twoway (scatter var1 var2) (lfit var1 var2), options (Harvard MIT Data Center) Stata Graphics 26 / 38
  • 27. Bivariate Graphics Overlaying Points and Lines twoway (scatter T_PERCAP T_VIOLNT) /// (lfit T_PERCAP T_VIOLNT), /// title("Comparison of Per Capita Income" /// "and Violent Crime Rate at Tract level") /// xtitle(Violent Crime Rate) ytitle(Per Capita Income) /// note(Source: National Neighborhood Crime Study 2000) (Harvard MIT Data Center) Stata Graphics 27 / 38
  • 28. Bivariate Graphics Overlaying Points and Labels twoway (scatter T_PERCAP T_VIOLNT if T_VIOLNT==1976, /// mlabel(CITY)) (scatter T_PERCAP T_VIOLNT), /// title("Comparison of Per Capita Income" /// "and Violent Crime Rate at Tract level") /// xlabel(0(200)2400) note(Source: National Neighborhood /// Crime Study 2000) legend(off) (Harvard MIT Data Center) Stata Graphics 28 / 38
  • 29. Bivariate Graphics Exercise 2: The TwoWay Family Open the datafile, NatNeighCrimeStudy.dta. 1 Create a basic twoway scatterplot that compares the city unemployment rate (C_UNEMP) to the percent secondary sector low-wage jobs (C_SSLOW) 2 Generate the same scatterplot, but this time, divide the plot by the dummy variable indicating whether the city is located in the south or not (C_SOUTH) 3 Change the color of the symbol that you use in this scatter plot 4 Change the type of symbol you use to a marker of your choice 5 Notice in your scatterplot that is broken down by C_SOUTH that there is an outlier in the upper right hand corner of the "Not South" graph. Add the city name label to this marker. 6 Review the options available under "help twowayoptions " and change one aspect of your graph using an option that we haven’t already reviewed (Harvard MIT Data Center) Stata Graphics 29 / 38
  • 30. More Fun with Twoway Line Graphs Topic 1 Introduction 2 Univariate Graphics 3 Bivariate Graphics 4 More Fun with Twoway Line Graphs 5 Wrap-up (Harvard MIT Data Center) Stata Graphics 30 / 38
  • 31. More Fun with Twoway Line Graphs Line Graphs Line graphs helpful for a variety of data Especially any type of time series data We’ll use data on US life expectancy from 1900-1999 webuse uslifeexp, clear (Harvard MIT Data Center) Stata Graphics 31 / 38
  • 32. More Fun with Twoway Line Graphs Line Graphs webuse uslifeexp, clear twoway (line le_wm year, mcolor("red")) /// (line le_bm year, mcolor("green")) (Harvard MIT Data Center) Stata Graphics 32 / 38
  • 33. More Fun with Twoway Line Graphs Line Graphs twoway (line (le_wfemale le_wmale le_bf le_bm) year, /// lpattern(dot solid dot solid)) (Harvard MIT Data Center) Stata Graphics 33 / 38
  • 34. More Fun with Twoway Line Graphs Stata Graphing Lines palette linepalette (Harvard MIT Data Center) Stata Graphics 34 / 38
  • 35. More Fun with Twoway Line Graphs Exporting Graphs From Stata, right click on image and select "save as" or try syntax: graph export myfig.esp, replace In Microsoft Word: insert > picture > from file Or, right click on graph in Stata and copy and paste into Word (Harvard MIT Data Center) Stata Graphics 35 / 38
  • 36. Wrap-up Topic 1 Introduction 2 Univariate Graphics 3 Bivariate Graphics 4 More Fun with Twoway Line Graphs 5 Wrap-up (Harvard MIT Data Center) Stata Graphics 36 / 38
  • 37. Wrap-up Help Us Make This Workshop Better Please take a moment to fill out a very short feedback form These workshops exist for you–tell us what you need! http://tinyurl.com/StataGraphicsFeedback (Harvard MIT Data Center) Stata Graphics 37 / 38
  • 38. Wrap-up Additional resources training and consulting IQSS workshops: http://projects.iq.harvard.edu/rtc/filter_by/workshops IQSS statistical consulting: http://rtc.iq.harvard.edu Stata resources UCLA website: http://www.ats.ucla.edu/stat/Stata/ Great for self-study Links to resources Stata website: http://www.stata.com/help.cgi?contents Email list: http://www.stata.com/statalist/ (Harvard MIT Data Center) Stata Graphics 38 / 38