-
Notifications
You must be signed in to change notification settings - Fork 169
/
ch03-height-income.do
97 lines (76 loc) · 3.18 KB
/
ch03-height-income.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
********************************************************************
* Prepared for Gabor's Data Analysis
*
* Data Analysis for Business, Economics, and Policy
* by Gabor Bekes and Gabor Kezdi
* Cambridge University Press 2021
*
* gabors-data-analysis.com
*
* License: Free to share, modify and use for educational purposes.
* Not to be used for commercial purposes.
*
* Chapter 03
* CH03D Distributions of body height and income
* using the height-indome-distribution dataset
* version 0.9 2020-09-06
********************************************************************
* SETTING UP DIRECTORIES
* STEP 1: set working directory for da_case_studies.
* for example:
* cd "C:/Users/xy/Dropbox/gabors_data_analysis/da_case_studies"
* STEP 2: * Directory for data
* Option 1: run directory-setting do file
do set-data-directory.do
/* this is a one-line do file that should sit in
the working directory you have just set up
this do file has a global definition of your working directory
more details: gabors-data-analysis.com/howto-stata/ */
* Option 2: set directory directly here
* for example:
* global data_dir "C:/Users/xy/gabors_data_analysis/da_data_repo"
global data_in "$data_dir/height-income-distributions/clean"
global work "ch03-distributions-height-income"
cap mkdir "$work/output"
global output "$work/output"
use "$data_in/hrs_height_income.dta",clear
* Normal distribution: height of women age 55-59
sum height if age>=55 & age<60 & female==1
tab height if height>1.80 & age>=55 & age<60 & female==1 ,mis
count if age>=55 & age<60 & female==1 & height>1.3
sum height if age>=55 & age<60 & female==1 & height>1.3
* Histogram with normal density overlayed
* Figure 3.10
colorpalette viridis, n(4) select(2) nograph
hist height if age>=55 & age<60 & female==1 & height>1.3 , ///
percent width(0.025) ///
color(`r(p)') lcol(white) ///
normal ///
ylabel(,grid) xlabel(1.4(0.1)1.9, grid) ///
xtitle("Body height")
graph export "$output/ch03-figure-10-hist-height-Stata.png", replace
* Lognormal distribution: family income of women age 55-59
* Histogram of income and ln income with normal density overlayed
* Figure 3.11a
count if age>=55 & age<60 & female==1
count if age>=55 & age<60 & female==1 & hhincome<1
count if age>=55 & age<60 & female==1 & hhincome>1000 & hhincome!=.
count if age>=55 & age<60 & female==1 & hhincome==.
count if age>=55 & age<60 & female==1 & hhincome>1 & hhincome<1000
colorpalette viridis, n(4) select(2) nograph
hist hhincome if age>=55 & age<60 & female==1 & hhincome>1 & hhincome<1000, ///
percent width(20) ///
color(`r(p)') lcol(white) lw(vvthin) ///
ylabel(0(5)25, grid) xlabel(0(200)1000, grid) ///
xtitle("Household income (thousand US dollars)")
graph export "$output/ch03-figure-11a-hist-inc-Stata.png", replace
* Figure 3.11b
gen lnincome=ln(hhincome)
lab var lnincome "ln(houehold income, thousand US dollars)"
colorpalette viridis, n(4) select(2) nograph
hist lnincome if age>=55 & age<60 & female==1 & lnincome>0 & hhincome<1000, ///
percent width(0.25) start(0) ///
color(`r(p)') lcol(white) ///
ylabel(0(2.5)10, grid) xlabel(0(1)8, grid) ///
normal
graph export "$output/ch03-figure-11b-hist-lninc-Stata.png", replace