Lab 4 (New)
Lab 4 (New)
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