-
Notifications
You must be signed in to change notification settings - Fork 0
/
_gclassify_sfga.ado
80 lines (69 loc) · 1.93 KB
/
_gclassify_sfga.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
capture program drop _gclassify_sfga
capture program drop SGA_Badsyntax
*! version 0.4.0 (SJxx-x: dmxxxx)
program define _gclassify_sfga
version 16
preserve
gettoken type 0 : 0
gettoken return 0 : 0
gettoken eqs 0 : 0
gettoken paren 0 : 0, parse("(), ")
gettoken input 0 : 0, parse("(), ")
gettoken paren 0 : 0, parse("(), ")
if `"`paren'"' != ")" {
error 198
}
syntax [if] [in], GEST_days(varname numeric) sex(varname) SEXCode(string) /*
*/ [SEVere by(string)]
if `"`by'"' != "" {
_egennoby classify_sfga() `"`by'"'
/* NOTREACHED */
}
local 1 `sexcode'
*zap commas to spaces (i.e. commas indulged)
local 1 : subinstr local 1 "," " ", all
tokenize `"`1'"', parse("= ")
if "`1'" == substr("male", 1, length("`1'")) {
if "`2'" ~= "=" | "`5'" ~= "=" | /*
*/ "`4'" ~= substr("female", 1, length("`4'")) | /*
*/ "`7'" ~= "" {
SGA_Badsyntax
}
local male "`3'"
local female "`6'"
}
else if "`1'" == substr("female",1,length("`1'")) {
if "`2'" ~= "=" | "`5'" ~= "=" | /*
*/ "`4'" ~= substr("male", 1, length("`4'") | /*
*/ "`7'" ~= "" {
SGA_Badsyntax
}
local male "`6'"
local female "`3'"
}
else SGA_Badsyntax
marksample touse
tempvar p_temp
qui {
egen double `p_temp' = ig_nbs(`input', "wfga", "v2c"), ///
gest_days(`gest_days') sex(`sex') sexcode(m="`male'", f="`female'")
generate `type' `return' = 0
replace `return' = -1 if float(`p_temp') < 0.1
replace `return' = 1 if float(`p_temp') > 0.9
replace `return' = . if missing(`p_temp') | `touse' == 0
}
cap la de sfga_labels -1 "SGA" 0 "AGA" 1 "LGA"
cap la de sev_sfga_labels -2 "severely SGA" -1 "SGA" 0 "AGA" 1 "LGA"
if "`severe'"=="" {
la val `return' sfga_labels
}
else {
replace `return' = -2 if float(`p_temp') < 0.03
la val `return' sev_sfga_labels
}
restore, not
end
program SGA_Badsyntax
di as err "sexcode() option invalid: see {help classify_sfga}"
exit 198
end