-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsiman_table.ado
162 lines (136 loc) · 5.4 KB
/
siman_table.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
*! version 0.11.2 28oct2024
* version 0.11.2 28oct2024 IW implement new concise option
* version 0.11.1 21oct2024 IW implement new dgmmissingok option
* version 0.8.3 3apr2024
* version 0.8.3 3apr2024 IW ignore method if methodcreated
* 14feb2024 IW allow new performance measure (pctbias) from simsum
* version 0.8.2 20dec2023 IW add row() option (undocumented at present)
* version 0.8.1 25oct2023 IW put PMs in same order as in simsum
* version 0.8 23dec2022 IW major rewrite: never pools over dgms, targets or methods
* version 0.7 05dec2022 EMZ removed 'if' condition, as already applied by siman analyse to the data (otherwise applying it twice).
* version 0.6 11july2022 EMZ changed generated variables to have _ infront
* version 0.5 04apr2022 EMZ changes to the default column/row and fixed bug in col() option.
* version 0.4 06dec2021 EMZ changes to the ordering of performance measures in the table (from TM testing). Allowed subset of perf measures to be * selected for the table display.
* version 0.3 25nov2021 EMZ changes to table output when >4 dgms/targets
* version 0.2 11June2020 IW changes to output format
* version 0.1 08June2020 Ella Marley-Zagar, MRC Clinical Trials Unit at UCL
program define siman_table
version 15
syntax [anything] [if], [Column(varlist) /// documented option
Row(varlist) debug pause CONcise /// undocumented options
]
// PARSING
foreach thing in `_dta[siman_allthings]' {
local `thing' : char _dta[siman_`thing']
}
* check if siman analyse has been run, if not produce an error message
if "`analyserun'"=="0" | "`analyserun'"=="" {
di as error "siman analyse has not been run. Please use siman analyse first before siman table."
exit 498
}
// PREPARE DATA
preserve
* remove underscores from variables est_ and se_ for long-long format
foreach val in `estimate' `se' {
if strpos("`val'","_")!=0 {
if substr("`val'",strlen("`val'"),1)=="_" {
local l = substr("`val'", 1,strlen("`val'","_") - 1)
local `l'vars = "`l'"
}
}
}
* choose sample
qui drop if `rep'>0
tempvar touse
marksample touse
* if the 'if' condition varies within dgm, method and target then write error
cap bysort `dgm' `method' `target' : assert `touse'==`touse'[1]
if _rc {
di as error "'if' can only be used for dgm, method and target."
exit 498
}
* if performance measures are not specified then display table for all of them, otherwise only display for selected subset
if "`anything'"!="" {
tempvar keep
gen `keep' = 0
foreach thing of local anything {
qui count if _perfmeascode == "`thing'"
if r(N)==0 di as smcl as text "{p 0 2}Warning: performance measure not found: `thing'{p_end}"
qui replace `keep' = 1 if _perfmeascode == "`thing'"
}
qui keep if `keep'
drop `keep'
}
* re-order performance measures for display in the table as per simsum
local perfvar = "estreps sereps bias pctbias mean empse relprec mse rmse modelse ciwidth relerror cover power"
qui gen _perfmeascodeorder=.
local p = 0
foreach perf of local perfvar {
qui replace _perfmeascodeorder = `p' if _perfmeascode == "`perf'"
local perflabels `perflabels' `p' "`perf'"
local p = `p' + 1
}
label define perfl `perflabels'
label values _perfmeascodeorder perfl
label variable _perfmeascodeorder "performance measure"
drop _perfmeascode
rename _perfmeascodeorder _perfmeascode
* sort out numbers of variables to be tabulated, and their levels
if `methodcreated' local method
* identify non-varying dgm
foreach onedgmvar in `dgm' {
qui levelsof `onedgmvar' `if', `dgmmissingok'
if r(r)>1 local newdgmvar `newdgmvar' `onedgmvar'
else if !mi("`debug'") di as input "Debug: ignoring non-varying dgmvar: `onedgmvar'"
}
local dgm `newdgmvar'
local myfactors _perfmeascode `dgm' `target' `method'
if !mi("`debug'") di as input "Debug: factors to display: `myfactors'"
tempvar group
foreach thing in dgm target method {
local n`thing'vars = wordcount("``thing''")
if !mi("`thing'") {
egen `group' = group(``thing''), `dgmmissingok'
qui levelsof `group'
local n`thing'levels = r(r)
}
else n`thing'levels = 1
if !mi("`debug'") di as input "Debug: `thing' has `n`thing'levels' levels, `n`thing'vars' variables (``thing'')"
drop `group'
}
* decide what to put in columns
if "`column'"=="" {
if `nmethodlevels'>1 local column `method'
else if `ntargetlevels'>1 local column `target'
else local column : word 1 of `dgm'
}
local myfactors : list myfactors - column
if "`row'"=="" {
if !strpos("`column'","perfmeas") local row _perfmeascode
else local row : word 1 of `myfactors'
}
local by : list myfactors - row
if wordcount("`by'")>4 {
di as error "There are too many factors to display. Consider using an if condition for your dgm."
}
* display the table
local tablecommand tabdisp `row' `column' `if', by(`by') c(`estimate' `se') stubwidth(20) `concise'
if !mi("`debug'") {
di as input "Debug: table features:"
di " column: `column'"
di " row: `row'"
di " by: `by'"
di `" command: `tablecommand'"'
}
if !mi("`pause'") {
global F9 `tablecommand'
pause Press F9 to recall, optionally edit and run the table command
}
`tablecommand'
* if mcses are reported, print the following note
cap assert missing(`se')
if _rc {
di as smcl as text "{p 0 2}{it: NOTE: Where there are 2 entries in the table, the first entry is the performance measure and the second entry is its Monte Carlo error.}{p_end}"
}
restore
end