0% found this document useful (0 votes)
10 views3 pages

Lab 4 (New)

This document discusses how to create various graphs in Stata, including histograms, bar graphs, box plots, and scatter plots. It uses Stata's auto and sample datasets to demonstrate how to generate one-way and two-way graphs, customize features like axis labels and colors, and group graphs by variables. Basic graphing commands in Stata include graph, histogram, bar, box, and twoway scatter. Options allow adding titles, changing symbols and colors, and presenting data grouped or stacked in the same graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Lab 4 (New)

This document discusses how to create various graphs in Stata, including histograms, bar graphs, box plots, and scatter plots. It uses Stata's auto and sample datasets to demonstrate how to generate one-way and two-way graphs, customize features like axis labels and colors, and group graphs by variables. Basic graphing commands in Stata include graph, histogram, bar, box, and twoway scatter. Options allow adding titles, changing symbols and colors, and presenting data grouped or stacked in the same graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 4.

do - Printed on 08/11/2023 5:41:31 pm


1 /*
2 Eeman Shahzad Qureshi
3 SDA Lab 4-Data Visualization
4 9th October 2023
5
6 */
7
8 *For STATA graphs:
9
10 *1) Graph command
11 *2) Graph type
12 *3) The variable name we want to use
13
14
15 *Help graph:
16
17 help graph
18
19 *Set scheme:
20
21
22 help set scheme
23 set scheme economist
24
25 net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
26
27 set scheme cleanplots
28
29 // Types of graphs in stata:
30
31 *1) One way graphs (Histogram, bar graph)
32 *2) Two way graphs (Scatter plots, line plots)
33
34
35 *Open Stata's dataset:
36
37 sysuse auto, clear
38
39 histogram price
40 histogram price, normal
41 histogram price, freq
42 sum price
43
44 *Open Stata's Dataset:
45
46 use "C:\Users\eeman.qureshi\Documents\STATA Fall Semester 2023\Lab 4\data1_sample.dta", clear
47
48 *Run this command (you don't need to know what this means:)
49
50 keep if hhsize == 1 & rent < 2000
51
52 *Graph bar
53
54 help graph bar
55
56 *Make bar graph of income:
57
58 graph bar income //shows mean of income
59
60 sum income
61
62 *If we want the average of income by state:
63

Page 1
Lab 4.do - Printed on 08/11/2023 5:41:31 pm
64 bysort state: sum income
65
66 *What if we want to see this in a graph form?
67
68 graph bar income, by(state)
69
70 *Presentable:
71
72 graph bar income, over(state)
73
74 *Horizontal axis:
75
76 graph hbar income, over(state)
77
78 *What if we want to see the total income by state:
79
80 graph hbar (sum) income, over(state)
81
82
83
84 *Show the average of income by state and gender
85
86 graph hbar income, over(state) by(sex) //by will make different windows and over will make it in
the same graph
87
88 graph hbar income, over(state) over(sex)
89 //this will stack state and sex in the same window and show mean on the x-axis
90
91
92 *What to do if I want the median income in the graph?
93
94 graph hbar (median) income, over (state)
95
96 *Check mean and median income together?
97
98 graph hbar (median) income (mean) income , over (state)
99
100 *OR
101 graph hbar income (median) income, over (state)
102
103 *Sum of income and mean in the same graph:
104
105 graph hbar (sum) income (mean) income , over (state)
106
107
108 *Box plot
109
110 graph box rent, by(state)
111
112 graph hbox rent, over(state)
113 graph hbox rent, over(state) noout
114
115 //Box plot shows the distribution in which median is the middle line with the box representing the
IQ range.
116
117
118 *Scatter Plots: they tell you the relationship between two variables?
119
120 *first y variable and then x-variable:
121
122 graph twoway scatter rent size
123
124 *how to get rent separately for different states?

Page 2
Lab 4.do - Printed on 08/11/2023 5:41:31 pm
125
126 graph twoway scatter rent size, by(state)
127
128 //The over option does not work for this graph
129
130
131 *Options: Change the dots of the graph
132
133 graph twoway scatter rent size, msymbol (t)
134 //triangles instead of dots
135
136 *change colours
137
138 help colorstyle
139 // to see the colours available in stata
140
141 graph twoway scatter rent size, mcolor(lavender)
142
143 //Triangles and colour change together
144
145 graph twoway scatter rent size, mcolor(lime) msymbol (t)
146
147 *Change intensity of the color:
148
149 graph twoway scatter rent size, mcolor(lime*0.5) msymbol (t)
150
151 //We can choose the colour intensity from 0.1-0.9- the lower the number the lower the
intensity of colour
152
153
154 *Add labels, titles, subtitles:
155
156 graph twoway scatter rent size, mcolor(lavender) msymbol (t) xtitle(Size) ytitle(rent) title
(rent vs size)
157
158
159
160
161
162

Page 3

You might also like