-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleaninc.ado
50 lines (36 loc) · 1.47 KB
/
cleaninc.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
* the program replace with missing or zero *(default: missing) if the income
* has got a structural problem i.e. is negative or if in case of the derived
* variables there is an inconsistency with the boolean value.
* to be sure that the program is not loaded in the stata memory
* capture program drop cleaninc
*! cleaninc v1.0.1 APizzigolotto 04aug2017
program define cleaninc
syntax varlist [, Myopt *]
* zero or missing (?)
scalar value = .
if "`options'" == "zeros" {
scalar value = 0
}
foreach i of local 0 {
if strpos("`i'", "di") | strpos("`i'", "pg") | strpos("`i'", "hg") {
* verify there's the booleanish alter ego of the income variable
capture confirm variable `i'i
if !_rc {
* replace with missing or zero if the boolean is zero and
* the variable is missing or the boolean is zero and the
replace `i' = value if (`i'i == 0 & missing(`i')) | `i' < 0
}
else {
* replace with missing or zero if missing or negative
replace `i' = value if `i' < 0 | missing(`i')
* total household gross income 2 has no boolean control, as well as net wealth
if "`i'" == "di2000" {
replace `i' = value if `i' == 0
}
}
}
else {
di "error: the variable `i' is not an income variable."
}
}
end