0% found this document useful (0 votes)
79 views33 pages

stata应用课程 作图

This document discusses types of graphs in Stata, including twoway plots, scatterplot matrices, bar charts, box plots, and pie charts. It provides examples of commands to create different types of graphs and customize them, such as setting schemes, adding titles and labels. The document concludes with an example application analyzing income and wealth inequality in America from 1949 to 2016 using Stata graphs.

Uploaded by

Mengdi Shi
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)
79 views33 pages

stata应用课程 作图

This document discusses types of graphs in Stata, including twoway plots, scatterplot matrices, bar charts, box plots, and pie charts. It provides examples of commands to create different types of graphs and customize them, such as setting schemes, adding titles and labels. The document concludes with an example application analyzing income and wealth inequality in America from 1949 to 2016 using Stata graphs.

Uploaded by

Mengdi Shi
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/ 33

Stata: Graphs

Zilin Wang
Types of Stata Graphs
• Twoway plot
– Including scatterplots, line plots, fit plots, fit plots
with confidence intervals, area plots, bar plots,
range plots, and distribution plots.
• Scatterplot matrices
• Bar charts
• Box plots
• Pie charts
Types of Stata Graphs

graph twoway scatter propval100 popden

twoway scatter propval100 popden

twoway lfit propval100 popden


Types of Stata Graphs

twoway (scatter propval100 popden) ///


(lfit propval100 popden) ///
(qfit propval100 popden)

twoway (scatter propval100 popden) ///


(lfitci propval100 popden)
Types of Stata Graphs

twoway line close tradeday, sort

twoway connected close tradeday, sort


Types of Stata Graphs

twoway area close tradeday

twoway bar close tradeday


Types of Stata Graphs

twoway histogram popk, freq

twoway kdensity popk


Types of Stata Graphs

graph matrix propval100 rent700 popden

graph hbar popk, over(division)


Types of Stata Graphs

graph hbox popk, over(division)


-nooutsides
-asyvars
-nofill

graph pie popk, over(region)


Schemes

Two ways to set schemes:

. set scheme vg s2c


Note: Subsequent graph commands will show graphs using the
vg s2c scheme.

. graph twoway scatter propval100 ownhome, scheme(vg s2c)


Note: In this way, the scheme will be used just for that graph.
Schemes

scheme vg s2c

scheme vg s2m
Schemes

scheme vg s1c

scheme vg s1m
Options

twoway scatter propval100 rent700,


title(“This is a title for the graph”, box
size(small)) msymbol(S))

twoway scatter propval100 rent700,


xlabel(0(5)40, labsize(huge))
Options

twoway scatter propval100


rent700 popden,
legend(cols(1) label(1 "Property
Value") label(2 "Rent"))

twoway (scatter propval100


popden, msymbol(S)) (lfit
propval100 popden,
clwidth(vthick)), title("This is the
title of the graph")
Application
Income and Wealth Inequality in America, 1949–2016

This paper introduces a new long-run data set based on archival data from
historical waves of the Survey of Consumer Finances. Studying the joint
distribution of household income and wealth, we expose the central importance
of portfolio composition and asset prices for wealth dynamics in postwar
America. Asset prices shift the wealth distribution because of systematic
differences in household portfolios along the wealth distribution. Middle-class
portfolios are dominated by housing, while rich households predominantly own
business equity. Differential changes in equity and house prices shaped wealth
dynamics in postwar America and decoupled the income and wealth distribution
over extended periods.
Population shares of age groups

Age 25-34 Age 65-99


.5 .5
Census share Census share
SCF+ share without adjustment SCF+ share without adjustment
SCF+ share with adjustment SCF+ share with adjustment
.4 .4

.3 .3

.2 .2

.1 .1

0 0
50

53

56

59

62

65

68

71

74

77

80

83

86

89

50

53

56

59

62

65

68

71

74

77

80

83

86

89
19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19
Population shares of college households,
and black households

College Black
.5 .5
Census share Census share
SCF+ share without adjustment SCF+ share without adjustment
SCF+ share with adjustment SCF+ share with adjustment
.4 .4

.3 .3

.2 .2

.1 .1

0 0
50

53

56

59

62

65

68

71

74

77

80

83

86

89

50

53

56

59

62

65

68

71

74

77

80

83

86

89
19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19

19
Population shares of college households,
and black households
.5
Census share
SCF+ share without adjustment
SCF+ share with adjustment
.4

.3

.2

.1

0
50

53

56

59

62

65

68

71

74

77

80

83

86

89
19

19

19

19

19

19

19

19

19

19

19

19

19

19
twoway connected CScollege yearmerge if (mod(yearmerge, 10) == 0), ///
msym(s) msize(medlarge) mfc(gs0) mlc(gs0) || ///
scatter share_college_oldwgt yearmerge if myear_ind == 1, msym(o) msize(large) mfc(red) mlc(red) || ///
scatter share_college_wgt yearmerge if myear_ind == 1, msym(d) msize(medlarge) mfc(blue) mlc(blue) ///
plotregion(color(white)) graphregion(color(white)) bgcolor(white) ///
xscale(r(1950 1990)) xlabel(1950(3)1990, angle(45)) yscale(r(0 0.5)) ///
ylabel(`ylab', angle(0)) xtitle("") ytitle("") ///
legend(ring(0) position(10) col(1) lab(1 "Census share") lab(2 "SCF+ share without adjustment") ///
lab(3 "SCF+ share with adjustment")) name("comp_census_`var'", replace)
graph export "${sav_dir}/comp_census_`var'.eps", replace
Comparison of income and wealth from
SCF1, NIPA, and FA data

Income Wealth
90 100 110 120 130 140 150

NIPA FA

100 125 150 175 200 225 250


SCF+ SCF+
80
70
60

75
50

50
40

1950 1960 1970 1980 1990 2000 2010 1950 1960 1970 1980 1990 2000 2010
Comparison of income and wealth from
SCF1, NIPA, and FA data

90 100 110 120 130 140 150


NIPA
SCF+

80
70
60
50
40

1950 1960 1970 1980 1990 2000 2010

twoway ///
connected SCFtinc_I year, msize(large) mcolor(gs0) || ///
line NIPAtinc_I year, lpattern("--") lwidth(thick) lcolor(blue)/*
*/ legend(bplacement(nw) ring(0) col(1) order(2 1) symxsize(8) lab(1 "SCF+") lab(2 "NIPA"))
xscale(r(1950 2014)) xlabel(1950(10)2014) xtitle("") /*
*/ yscale(r(40 150)) ylabel(40(10)150) ytitle("") /*
*/ name("TINC_indexed", replace) scheme(s2mono) graphregion(color(white)) bgcolor(white)
graph export "${sav_dir}/SCF_NIPA_income_indexed.eps", replace
Gini coefficients for income and wealth
with 90% confidence bands

Income Wealth
.6 .95

.9
.55

.85
.5

.8

.45
.75

.4
.7

.35 .65
1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015 1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015
Gini coefficients for income and wealth
with 90% confidence bands
.6

.55

.5

.45

.4

.35
1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015
#delimit;
graph twoway
(rarea gini_tinc_lb gini_tinc_ub year, fcolor(eltblue) lcolor(eltblue) )
(connected gini_tinc yearmerge, mc(blue) msym(O) msize(large) lc(blue) lwidth(thick)),
xscale(r(1950 2016)) xlabel(1950(5)2015, labsize(medium)) xsize(6.5) xtitle("")
ytitle("",size(medlarge)) ylabel(0.35(0.05)0.6,angle(0) labsize(medium)) legend(off)
graphregion(color(white)) plotregion(margin(zero)) name("gini_tinc_CIs", replace)
;#delimit cr
graph export "${sav_dir}/gini_tinc_CIs.eps", replace
Percentile ratios for income and wealth

Income Wealth
2.5

3.5

5
50−25 ratio (left axis) 50−25 ratio (left axis)

12
75−50 ratio (right axis) 75−50 ratio (right axis)

11
90−50 ratio (right axis) 90−50 ratio (left axis)

10

4
2

9
2.5

3
7
2
1.5

2
1.5

5
4
1

1
1950 1960 1970 1980 1990 2000 2010 1950 1960 1970 1980 1990 2000 2010
Percentile ratios for income and wealth

2.5

3.5
50−25 ratio (left axis)
75−50 ratio (right axis)
90−50 ratio (right axis)

3
2

2.5
2
1.5

1.5
1

1
1950 1960 1970 1980 1990 2000 2010

twoway ///
line p5025income yearmerge , lwidth(thick) lpattern("l") lc(blue) xscale(r(1949 2017))
xlabel(1950(10)2010) xtitle("") || ///
line p7550income yearmerge , yaxis(2) lwidth(thick) lpattern("--") lc(red) || ///
line p9050income yearmerge , yaxis(2) lwidth(thick) lpattern("_") lc(black) /*
*/ yscale(r(1 2.5) axis(1)) yscale(r(1 3.5) axis(2)) ylabel(1(0.5)2.5, axis(1)) ylabel(1(0.5)3.5, axis(2))/*
*/ scheme(s2mono) graphregion(color(white)) bgcolor(white) ytitle("", axis(1)) ytitle("", axis(2)) /*
*/ legend(bplacement(nw) ring(0) col(1) lab(1 "50-25 ratio (left axis)") lab(2 "75-50 ratio (right axis)")
lab(3 "90-50 ratio (right axis)")) name("bottomincome", replace)
graph export "${sav_dir}/QuantileRatiosBottom90income.eps", replace
0 .1 .2 .3 .4
19
50
19
53
19
56
19
59
19
62
19
65
19
68
19
71
19
83
19

wealthy HtM
89
19
92
19
95
19
98
20
01
20
poor HtM 04
20
07
20
households (HtM)

10
20
13
20
16
Shares of poor and wealthy hand-to-mouth
Shares of poor and wealthy hand-to-mouth
households (HtM)

.4
.3
.2
.1
0

50
53
56
59
62
65
68
71
83
89
92
95
98
01
04
07
10
13
16
19
19
19
19
19
19
19
19
19
19
19
19
19
20
20
20
20
20
20
wealthy HtM poor HtM

graph bar Wh2m Ph2m, over(year, gap(*0.6) label(angle(45)) ) stack ///


bar(1, color(red*0.8) lc(black)) bar(2, color(blue) lc(black)) ///
plotregion(color(white)) graphregion(color(white)) bgcolor(white) ///
legend(label(1 "wealthy HtM") label(2 "poor HtM")) ysc(r(0 0.4)) ///
ylabel(0(0.1)0.4) ytitle("") name("HtM_HSCF_`incvar'_`cash_adj'_`sample'", replace)
graph export "${sav_dir}/HtM_HSCF_`incvar'_`cash_adj'_`sample'.eps", replace
Income and wealth growth for different
groups along the wealth distribution
Income Wealth
2.5

3
2.5
2

2
1.5

1.5
1

1
.5

.5
0
0

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015 1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015

0% − 50% 50% − 90% Top 10% 0% − 50% 50% − 90% Top 10%
Income and wealth growth for different
groups along the wealth distribution

2.5
2
1.5
1
.5
0

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015

0% − 50% 50% − 90% Top 10%

twoway line inc_rel year if ffanwgroups == 1, lc(gs0) lp(solid) lwidth(thick) || ///


line inc_rel year if ffanwgroups == 2, lc(blue) lp(shortdash) lwidth(thick) || ///
line inc_rel year if ffanwgroups == 3, lc(red) lp(longdash) lwidth(thick) ///
xline(2007, lc(black) lp(shortdash)) ///
yscale(r(0 2.5)) ylabel(0(0.5)2.5) xscale(r(1950 2016)) xlabel(1950(5)2015) ///
legend(row(1) lab(1 "0% - 50%") lab(2 "50% - 90%") lab(3 "Top 10%")) ///
graphregion(color(white)) bgcolor(white) xtitle("") ytitle("") name(”inc_growth_nw", replace)
graph export "${sav_dir}/`gname'.eps", replace
Shares in total asset holdings by wealth
group for 1950, 1971, and 2007

1950 1971 2007

housing housing housing

stocks stocks stocks

0 20 40 60 80 100 0 20 40 60 80 100 0 20 40 60 80 100

bottom 50% 50% − 90% top 10%


Shares in total asset holdings by wealth
group for 1950, 1971, and 2007
1950 1971 2007

housing housing housing

stocks stocks stocks

0 20 40 60 80 100 0 20 40 60 80 100 0 20 40 60 80 100

bottom 50% 50% − 90% top 10%

foreach cyear of numlist 1950 1971 2007 {


graph hbar ac1 ac2 ac3 if year == `cyear', over(assetclass, label(labsize(vlarge))) ///
stack bar(1, color(gs16) lc(gs0) lwidth(medthick)) bar(2, color(blue) lc(gs0) ///
lwidth(medthick)) bar(3, color(red*0.8) lc(gs0) lwidth(medthick)) ///
legend(lab(3 "top 10%") lab(2 "50% - 90%") lab(1 "bottom 50%") row(1)) graphregion(color(white)) ///
bgcolor(white) ytitle("") title("`cyear'", size(huge)) name("assetdistribution_`cyear'", replace) nodraw
}
grc1leg assetdistribution_1950 assetdistribution_1971 assetdistribution_2007, ///
rows(1) graphregion(color(white)) xsize(4) ysize(3) ///
name("assetdistribution_all", replace) position (6)
graph display, xsize(3) ysize(1)
graph export "${sav_dir}/assetdistribution_all.eps", replace
Heterogeneity in household portfolios for
different groups along the wealth distribution

Bottom 50% 50% - 90%


14

5 10 15 20 25 30 35 40 45 50 55 60
Assets: Debt: Assets: Debt:
housing + non−fin. assets housing debt housing + non−fin. assets housing debt
12

stocks + business non−housing debt stocks + business non−housing debt


bonds + liquid and oth. fin. assets bonds + liquid and oth. fin. assets
10
8 6
x 10,000

x 10,000
2 4
0
−2

−10 −5 0
−4
−6

1950 1960 1970 1980 1990 2000 2010 1950 1960 1970 1980 1990 2000 2010
Heterogeneity in household portfolios for
different groups along the wealth distribution

Top 10% All households


560

100
Assets: Debt: Assets: Debt:
housing + non−fin. assets housing debt housing + non−fin. assets housing debt
480

stocks + business non−housing debt stocks + business non−housing debt


bonds + liquid and oth. fin. assets bonds + liquid and oth. fin. assets

80
400

60
240 320
x 10,000

x 10,000
40
160

20
80

0
0

−20

1950 1960 1970 1980 1990 2000 2010 1950 1960 1970 1980 1990 2000 2010
Heterogeneity in household portfolios for
different groups along the wealth distribution

100
Assets: Debt:
housing + non−fin. assets housing debt
stocks + business non−housing debt
bonds + liquid and oth. fin. assets

80 60
x 10,000
40 20
0
−20

1950 1960 1970 1980 1990 2000 2010

twoway area assetstack6 year, color(eltblue) lcolor(gs0) /*


*/ || area assetstack4 year, color(blue) lcolor(gs0) /*
*/ || area assetstack2 year, color(navy) lcolor(gs0) /*
*/ || area debtstack2 year, color(ebblue) lcolor(gs0) /*
*/ || area debtstack1 year, color(eltblue) lcolor(gs0) /*
*/ || line wealth year, lc(red) lwidth(vthick) lpattern(--) /*
*/ legend(ring(0) cols(2) colfirst holes(8) position(11) size(small) /*
*/ symysize(3) symxsize(4) rowgap(1) order(- "{it:Assets:}"1 2 3 - "{it:Debt:}" 5 4) /*
*/ lab(1 "housing + non-fin. assets") lab(2 "stocks + business") /*
*/ lab(3 "bonds + liquid and oth. fin. assets ") lab(4 "non-housing debt") lab(5 "housing debt") ) /*
*/ yscale(r(-15 105)) ylabel(-20(20)100) xtitle("") ytitle("x 10,000") /*

You might also like