-
Notifications
You must be signed in to change notification settings - Fork 2
/
filter_pers.do
55 lines (49 loc) · 1.29 KB
/
filter_pers.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
// import individual socio-economic data
use ../BATS96/compPER, clear
sort sampno
// if with_dist == 1, then
// calculate the eocnomic distance based on working time span
local with_dist 0
******** merge work activity
if `with_dist' == 1 {
merge 1:1 sampno persno using filtered_work
tab _merge
keep if _merge == 3
drop _merge
}
******** filter household heads
// replace missing variables
// replace age = . if age == 999
// replace income = . if income == 98 | income == 99
// remove missing observations
drop if age == 999
drop if income == 98 | income == 99
drop if employ == 3 | gender == 3 | student == 3
drop if license == 3
// only consider the household heads
keep if relate < 2
by sampno: gen numpers = _N
keep if numpers == 2
by sampno: gen has_spouse = sum(relate==1)
by sampno: replace has_spouse = has_spouse[_N]
keep if has_spouse == 1
******** calculate economic distance
// number of persons in each household
qui tab relate
global N = r(r)
// generate household working time span
sort sampno persno
by sampno: gen persid = _n
if `with_dist' == 1 {
forvalues j = 1/$N {
by sampno: gen dist_`j' = max(ending[_n], ending[`j']) - ///
min(begin[_n], begin[`j'])
}
}
else {
forvalues j = 1/$N {
by sampno: gen dist_`j' = 0
}
}
// save refined data
save dat/filtered_pers, replace