-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagebrackets.ado
62 lines (50 loc) · 2.78 KB
/
agebrackets.ado
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
********************************************************************************
* This is a simple program to generate age brackets grouping the household *
* reference person's age in ten-years cohorts. *
* To do so, we follow the codes in the second wave codebook of the HFCS. *
* *
* output is a variable ageRange which contains the age cohorts values. *
* *
* ECB - v 1.0 2017/08/04 - Alessandro Pizzigolotto *
* *
********************************************************************************
* to be sure that the program is not loaded in the stata memory
* capture program drop agebrackets
*! agebrackets v1.0.1 APizzigolotto 04aug2017
program define agebrackets
syntax varlist
capture confirm variable ageRange
if !_rc {
di "The age brackets were already determined. Overwrite."
* exit _rc works as a break inside the condition
capture novarabbrev drop ageRange
}
* if age < 16 or missing we don't count it.
gen ageRange = .
* age variable (canberra or not)
if "`varlist'" == "dhageh" | "`varlist'" == "dhageh1" | "`varlist'" == "dhageh2" | "`varlist'" == "dhageh3" | "`varlist'" == "ra0300" {
replace ageRange = 1 if `varlist' > 15 & `varlist' < 35
replace ageRange = 2 if `varlist' > 34 & `varlist' < 45
replace ageRange = 3 if `varlist' > 44 & `varlist' < 55
replace ageRange = 4 if `varlist' > 54 & `varlist' < 65
replace ageRange = 5 if `varlist' > 64 & `varlist' < 75
replace ageRange = 6 if `varlist' > 74
}
* TODO: there is a problem with the labels, they are mismatched
* if we pass a pre-compiled age brackets variable (canberra or not)
else if "`varlist'" == "dhagehb" | "`varlist'" == "dhageh1b" | "`varlist'" == "dhageh2b" | "`varlist'" == "dhageh3b" {
replace ageRange = 1 if `varlist' == 16 | `varlist' == 20 | `varlist' == 25 | `varlist' == 30
replace ageRange = 2 if `varlist' == 35 | `varlist' == 40
replace ageRange = 3 if `varlist' == 45 | `varlist' == 50
replace ageRange = 4 if `varlist' == 55 | `varlist' == 60
replace ageRange = 5 if `varlist' == 65 | `varlist' == 70
replace ageRange = 6 if `varlist' == 75 | `varlist' == 80 | `varlist' == 85
}
else {
di "error: age variable not found. no variable created."
}
capture label drop ageRange_`varlist'
* label define ageRange_`varlist' 1 "16-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65-74" 7 "75+"
label define ageRange_`varlist' 1 "16-34" 2 "35-44" 3 "45-54" 4 "55-64" 5 "65-74" 6 "75+"
label values ageRange ageRange_`varlist'
end