0% found this document useful (0 votes)
3 views

Plottingstata

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Plottingstata

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Stata_plotting - Printed on 7/4/2023 10:27:44 PM

1 ***** GRAPHING *******


2
3
4 clear all
5
6 * cd "D:\...\Stata Plotting"
7
8
9 **************************************************************
10
11
12 * Load data set
13 sysuse auto.dta
14
15 **************************************************************
16 *** Histogram
17 **************************************************************
18
19 histogram mpg
20
21 * Adding options (axis title)
22 histogram mpg, xtitle("Miles Per Gallon")
23
24 **************************************************************
25 *** Scatterplots ***
26 **************************************************************
27
28 *simple scatter plot
29 scatter mpg weight
30
31 * multiple x variables
32 scatter mpg headroom weight
33
34 * Subset the data and add options
35 scatter mpg weight in 1/15, mlabel(make)
36
37 * Changing options of marker
38 scatter mpg weight, msymbol(circle_hollow) mcolor(red)
39
40 * change color and shape
41 twoway scatter mpg price
42
43 **************************************************************
44 *** Line Graphs ***
45 **************************************************************
46
47 webuse uslifeexp
48 line le year
49
50 * Again, multiple variables, and legends
51 webuse uslifeexp
52 line le le_male le_female year, legend(size(medsmall))
53
54 * Connected line graphs
55 webuse sp500
56 twoway connected high low date in 1/15
57
58
59 **************************************************************
60 * Two scatter plots in one (combining plots) and lines of best fit *
61 **************************************************************
62
63

Page 1
Stata_plotting - Printed on 7/4/2023 10:27:44 PM
64 sysuse auto
65 twoway (scatter mpg weight) (lfit mpg weight)
66
67 * OR
68 twoway scatter mpg weight || lfit mpg weight
69
70 * editing legend (options for each graph)
71 twoway (scatter mpg weight, legend(label(1 "MPG"))) ///
72 (lfit mpg weight, legend(label(2 "Line of best fit")))
73
74 * Options for whole graph changing overall color schemes
75 twoway (scatter mpg headroom, legend(label(1 "head room"))) ///
76 (scatter mpg trunk, legend(label(2 "trunk room"))), scheme(s1mono)
77
78 **************************************************************
79 * Boxplots
80 **************************************************************
81
82
83 webuse bpwide
84 graph box bp_before bp_after
85
86
87 **************************************************************
88 *** Bar graphs
89 **************************************************************
90
91
92 webuse citytemp
93 graph bar tempjan, over(region) // necessary. what are the groups you are interested in seeing.
94
95 * if you want to add labels
96 webuse citytemp
97 graph bar tempjan, over(region) blabel(total)
98
99
100
101

Page 2

You might also like