-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstata_ba_table.do
79 lines (78 loc) · 3.06 KB
/
stata_ba_table.do
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
// stata_ba_table
********************************
// [stata_ba_table.do]
// Author: ADH
// Date: 08/07/22
// Description: 'Table of results for Bland Altman analysis using concord'
// using multiple variables for comparison
// version 1.0
********************************
// standard settings
version 17
//clear all
//macro drop _all
//set linesize 80
//set more off
//pause on
********************************
// Requirements
/* user written code concord is required (Nicholas J. Cox & Thomas Steichen, 2000. "CONCORD: Stata module for concordance correlation,"
Statistical Software Components S404501, Boston College Department of Economics, revised 09 Aug 2007) http://www.stata-journal.com/software/sj10-4 */
net install st0015_6.pkg
********************************
cd c:\data // ensure you are in appropriate data folder (most installations have this and it should work for the example but this may need to be edited)
// modify the next line to use your dataset rather than the example dataset.
// This is only included for the purpose of the example.
import delimited "https://raw.githubusercontent.com/Lifelong-Health-Ageing/StataTables/main/data/Bland_pefr.csv?token=GHSAT0AAAAAAB2MHTX2ZY6WRF53BQRHCXC2Y4IWA3A", clear
********************************
// set up locals
local varlist w_pefr mw_pefr // we omit the number of the observation so we can include that in the loop
local labellist `" "Wright Flow meter PEFR" "Mini-Wright Flow meter PEFR" "'
local collist `" "Variable" "Mean difference" "Lower limit of agreement" "Upper limit of agreement" "Lin's CCC" "'
local totalrows = 3 // this should be the number of variables + 1 (for the title)
local totalcolumns = 5 // this should be the number of column labels
local row = 1 // start values
local col =1
local j = 1 //the number of the first observation (e.g. w_pefr1)
local k = 2 //the number of the second observation (e.g. w_pefr2)
*********************************
// start putdocx
putdocx clear
putdocx begin
putdocx paragraph
putdocx text ("Table 2. Reproducibility of measures"), bold
putdocx table tbl2 = (`totalrows', `totalcolumns')
*********************************
// Label variables in rows
foreach rlbl of local labellist {
//local row = `row'+1
local ++row // increments row
putdocx table tbl2(`row',1) = ("`rlbl'")
}
// Label columns
foreach clbl of local collist {
putdocx table tbl2(1,`col') = ("`clbl'")
local ++col
}
**********************************
// do loop for concord
local row = 1 // reset row
foreach x of local varlist {
local ++row
concord `x'`j' `x'`k'
local col=1
local results `r(diff)' `r(LOA_ll)' `r(LOA_ul)' `r(rho_c)'
foreach cell of local results {
local ++col
//disp `cell'
putdocx table tbl2(`row',`col') = (`cell')
}
}
*********************************
// Prettify the table
// format the decimal places
putdocx table tbl2(.,2/4), nformat(%10.1f)
putdocx table tbl2(.,5), nformat(%10.2f)
*********************************
// save putdocx
putdocx save ba_table.docx, replace