-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphCodingSample.do
118 lines (102 loc) · 8.61 KB
/
GraphCodingSample.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Analysis of Wealth Inequality by Race, Education, and Age
// Author: Bennett Smith-Worthington, Columbia University
// Date: Oct. 26, 2021
clear all
use RA_21_22
// Dividing all monetary variables by 1000 -> new unit is thousands of US $
replace asset_total = asset_total/1000
replace asset_housing = asset_housing/1000
replace debt_total = debt_total/1000
replace debt_housing = debt_housing/1000
replace income = income/1000
/*
SECTION 1: Key trends in median total wealth over the last 30 years by race and education
*/
preserve
// generating total_wealth var: = assets-debt
gen total_wealth = (asset_total - debt_total) // unweighted total wealth
egen med_wealth = median(total_wealth), by(year race education)
collapse med_wealth, by(year race education)
sort year
// Graphing total_wealth by racial and educational categories
// Plot 1: Median Wealth by Race and Education
/* key:
lpattern: solid line := college degree, longdash_dot := some college
dotted line := no college
lcolor: Hispanic := dkgreen, white := blue, black := red
*/
twoway (line med_wealth year if race == "black" & education == "no college", lcolor(red) lwidth(medthick) lpattern(dash)) ///
(line med_wealth year if race == "black" & education == "some college", lcolor(red) lwidth(medthick) lpattern(longdash_dot)) ///
(line med_wealth year if race == "black" & education == "college degree", lcolor(red) lwidth(medthick) lpattern(solid)) ///
(line med_wealth year if race == "Hispanic" & education == "no college", lcolor(dkgreen) lwidth(medthick) lpattern(dash)) ///
(line med_wealth year if race == "Hispanic" & education == "some college", lcolor(dkgreen) lwidth(medthick) lpattern(longdash_dot)) ///
(line med_wealth year if race == "Hispanic" & education == "college degree", lcolor(dkgreen) lwidth(medthick) lpattern(solid)) ///
(line med_wealth year if race == "white" & education == "no college", lcolor(blue) lwidth(medthick) lpattern(dash)) ///
(line med_wealth year if race == "white" & education == "some college", lcolor(blue) lwidth(medthick) lpattern(longdash_dot)) ///
(line med_wealth year if race == "white" & education == "college degree", lcolor(blue) lwidth(medthick) lpattern(solid) title(Median Wealth by Race and Education 1989-2016) ytitle(Median Wealth (2016 `$')) xtitle(Year) legend(order(1 "Black, No college" 2 "Black, Some college" 3 "Black, College degree" 4 "Hispanic, No college" 5 "Hispanic, Some college" 6 "Hispanic, College degree" 7 "White, No college" 8 "White, Some college" 9 "White, College degree")) )
// saving graph
graph save inequality_graph1, replace
restore
/*
SECTION 2: Inequality between Black and white people
*/
preserve
keep if race == "black" | race == "white"
gen housing_wealth = asset_housing - debt_housing
collapse (median) housing_wealth, by(race year education)
// Only looking at median housing wealth for Black/white households by
// levels of educational attainment
// Plot 2: median housing wealth for black and white households
twoway (line housing_wealth year if race == "black" & education == "no college", lcolor(red) lwidth(medthick) lpattern(dash)) ///
(line housing_wealth year if race == "black" & education == "some college", lcolor(red) lwidth(medthick) lpattern(longdash_dot)) ///
(line housing_wealth year if race == "black" & education == "college degree", lcolor(red) lwidth(medthick) lpattern(solid)) ///
(line housing_wealth year if race == "white" & education == "no college", lcolor(blue) lwidth(medthick) lpattern(dash)) ///
(line housing_wealth year if race == "white" & education == "some college", lcolor(blue) lwidth(medthick) lpattern(longdash_dot)) ///
(line housing_wealth year if race == "white" & education == "college degree", lcolor(blue) lwidth(medthick) lpattern(solid) title(Median Housing Wealth for Blacks/Whites by Education 1989-2016) ytitle(Median Housing Wealth (2016 `$')) xtitle(Year) legend(order(1 "Black, No college" 2 "Black, Some college" 3 "Black, College degree" 4 "White, No college" 5 "White, Some college" 6 "White, College degree")) )
graph save inequality_graph2, replace
restore
/*
SECTION 3: Analyzing wealth of Black/white people > 25 years old
*/
preserve
keep if race == "black" | race == "white"
keep if age>=25
gen housing_wealth = asset_housing - debt_housing
egen med_housing_wealth = median(housing_wealth), by(year race education)
collapse housing_wealth, by(race year education)
// Calculating losses in housing wealth by group, comparing 2007 to 2010
gen housing_wealth_lag = housing_wealth[_n-1] //housing wealth for year t-3
gen housing_wealth_change = housing_wealth - housing_wealth_lag
gen housing_wealth_change_perc = 100*((housing_wealth - housing_wealth_lag)/housing_wealth_lag)
// Plot 3: housing_wealth_change for black and white households over age of 25
twoway (line housing_wealth_change year if race == "black" & education == "no college", lcolor(red) lwidth(medthick) lpattern(dash)) ///
(line housing_wealth_change year if race == "black" & education == "some college", lcolor(red) lwidth(medthick) lpattern(longdash_dot)) ///
(line housing_wealth_change year if race == "black" & education == "college degree", lcolor(red) lwidth(medthick) lpattern(solid)) ///
(line housing_wealth_change year if race == "white" & education == "no college", lcolor(blue) lwidth(medthick) lpattern(dash)) ///
(line housing_wealth_change year if race == "white" & education == "some college", lcolor(blue) lwidth(medthick) lpattern(longdash_dot)) ///
(line housing_wealth_change year if race == "white" & education == "college degree", lcolor(blue) lwidth(medthick) xline(2007) lpattern(solid) title(Median Housing Wealth Change for Blacks and Whites (Age>25) 1989-2016) ytitle(Median Housing Wealth (2016 Thousands of `$')) ylabel(#5) xtitle(Year) legend(order(1 "Black, No college" 2 "Black, Some college" 3 "Black, College degree" 4 "White, No college" 5 "White, Some college" 6 "White, College degree")) )
graph save inequality_graph5, replace
// Plot 4: median housing wealth for black and white households over age of 25
twoway (line housing_wealth year if race == "black" & education == "no college", lcolor(red) lwidth(medthick) lpattern(dash)) ///
(line housing_wealth year if race == "black" & education == "some college", lcolor(red) lwidth(medthick) lpattern(longdash_dot)) ///
(line housing_wealth year if race == "black" & education == "college degree", lcolor(red) lwidth(medthick) lpattern(solid)) ///
(line housing_wealth year if race == "white" & education == "no college", lcolor(blue) lwidth(medthick) lpattern(dash)) ///
(line housing_wealth year if race == "white" & education == "some college", lcolor(blue) lwidth(medthick) lpattern(longdash_dot)) ///
(line housing_wealth year if race == "white" & education == "college degree", lcolor(blue) lwidth(medthick) xline(2007) lpattern(solid) title(Median Housing Wealth for Blacks and Whites (Age>25) 1989-2016) ytitle(Median Housing Wealth (2016 `$')) xtitle(Year) legend(order(1 "Black, No college" 2 "Black, Some college" 3 "Black, College degree" 4 "White, No college" 5 "White, Some college" 6 "White, College degree")) )
graph save inequality_graph3, replace
restore
// Plot 5: median non-housing wealth for black and white households over age of 25
preserve
keep if race == "black" | race == "white"
keep if age >= 25
gen non_housing_assets = asset_total - asset_housing
gen non_housing_debts = debt_total - debt_housing
gen non_housing_wealth = non_housing_assets - non_housing_debts
collapse (median) non_housing_wealth, by(race year education)
twoway (line non_housing_wealth year if race == "black" & education == "no college", lcolor(red) lwidth(medthick) lpattern(dash)) ///
(line non_housing_wealth year if race == "black" & education == "some college", lcolor(red) lwidth(medthick) lpattern(longdash_dot)) ///
(line non_housing_wealth year if race == "black" & education == "college degree", lcolor(red) lwidth(medthick) lpattern(solid)) ///
(line non_housing_wealth year if race == "white" & education == "no college", lcolor(blue) lwidth(medthick) lpattern(dash)) ///
(line non_housing_wealth year if race == "white" & education == "some college", lcolor(blue) lwidth(medthick) lpattern(longdash_dot)) ///
(line non_housing_wealth year if race == "white" & education == "college degree", lcolor(blue) lwidth(medthick) lpattern(solid) xline(2007, lwidth(thin) lcolor(black)) title(Median Non-Housing Wealth for Blacks and Whites (Age>25) 1989-2016) ytitle(Median Housing Wealth (2016 `$')) xtitle(Year) legend(order(1 "Black, No college" 2 "Black, Some college" 3 "Black, College degree" 4 "White, No college" 5 "White, Some college" 6 "White, College degree")) )
restore