-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsiman_import.ado
More file actions
143 lines (122 loc) · 4.14 KB
/
Copy pathsiman_import.ado
File metadata and controls
143 lines (122 loc) · 4.14 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
*! version 1.1 18dec2025
* version 1.1 18dec2025 resubmit to SJ
* version 1.0 24jul2025 submit to SJ
* v0.11.1 11apr2025 IW remove unwanted output, add level(), call siman describe
* v0.11 27mar2025 IW Broaden to include missing dgm/target/method and all method types; test properly
* v0.1 28oct2024 IW Rough starter
* Import dataset of performance statistics into siman format
prog def siman_import
syntax, Perf(varname string) ESTimate(varname numeric) [Dgm(varlist) TArget(varname) Method(varname) se(varname numeric) TRue(varname numeric) Level(real 0)]
// Create locals to store characteristics
* DGMs
local dgm `dgm'
local ndgmvars : word count `dgm'
local dgmmissingok
* TARGETS
if !mi("`target'") {
qui levelsof `target', clean
local numtarget = r(r)
local targetnature 0
local valtarget = r(levels)
}
* METHODS
if !mi("`method'") {
cap confirm string var `method'
if !_rc local methodnature 2
else local methodnature = !mi("`: value label `method''")
qui levelsof `method', clean
local nummethod = r(r)
if `methodnature'==1 { //
foreach i in `r(levels)' {
local valmethod `valmethod' `: label (`method') `i''
}
}
else local valmethod = r(levels)
local methodcreated 0
}
* PMs - uses list from simsum of PMs allowed
qui replace `perf' = "estreps" if `perf' == "bsims"
qui replace `perf' = "sereps" if `perf' == "sesims"
local pmsallowed estreps sereps bias pctbias mean empse relprec mse rmse modelse ciwidth relerror cover power
qui levelsof `perf', local(pmsindata) clean
local pmsbad : list pmsindata - pmsallowed
if !mi("`pmsbad'") {
di as error "Performance measures not allowed: `pmsbad'"
exit 498
}
local pmsneedlevel cover power
local pmsneedlevel : list pmsindata & pmsneedlevel
if !mi("`pmsneedlevel'") { // set characteristic cilevel
if `level'==0 {
local level $S_level
di as text "Assuming coverage/power were calculated at `level'% level"
}
local cilevel `level'
}
* Estimates
local estimate `estimate'
local se `se'
* Data formats
local setuprun 0
* Characteristics
local analyserun 1
local secreated
// Create rep variable
encode `perf', gen(rep0)
gen _rep = - rep0
labelit _rep `perf' // IW command below
drop rep0
local rep _rep
qui rename `perf' _perfmeascode
// Store as siman characteristics
local allthings dgm ndgmvars dgmmissingok target numtarget targetnature valtarget method nummethod methodnature valmethod methodcreated estimate se rep true setuprun analyserun secreated cilevel allthings
foreach char of local allthings {
char _dta[siman_`char'] ``char''
}
siman describe
end
/******************************************************************************/
* version 2.2 13feb2018 - label name is just var2 (otherwise can be too long)
* version 2.1 11feb2013 - blank labels for empty strings
* version 2 15dec2005 - if, in, check for duplications
prog def labelit
version 15
syntax varlist(min=2 max=2) [if] [in], [modify usefirst noBLAnks]
tokenize "`varlist'"
confirm numeric variable `1'
confirm string variable `2'
marksample touse, novarlist
qui summ `1' if `touse'
local imin=r(min)
local imax=r(max)
tempvar id
gen `id'=_n
forvalues i = `imin'/`imax' {
qui summ `id' if `1'==`i' & `touse'
if r(N)>0 {
local doit 1
local j=r(min)
local value = `2'[`j']
cap assert `2'=="`value'" if `1'==`i' & `touse'
if _rc>0 {
di as text "Warning: multiple values of `2' found for `1'==`i'"
tab `2' if `1'==`i' & `touse', missing
if "`usefirst'"!="usefirst" {
di as error "To use the first value, specify usefirst option"
exit 498
}
else di as text "Using the first value, `2'=`value'"
}
if "`value'"~="" local label `label' `i' "`value'"
else if "`blanks'"!="noblanks" local label `label' `i' " "
cap assert `2'=="`value'" if `1'==`i'
if _rc>0 {
di as text "Warning: multiple values of `2' for `1'==`i' - but only outside if/in expression"
label var `touse' "to use"
tab `2' `touse' if `1'==`i', missing
}
}
}
label def `2' `label', `modify'
label val `1' `2'
end