*! Version 1.0.1 [STB-51: sbe30] prog define oddsrcii *! Confidence intervals for the odds ratio of a 2x2 table; immediate *! Syntax: . oddsrcii [, LEVel(.xxx) NOTable *! TABopt(tabi options) NONE ALL AGresti COrnf GArt WOolf ] * John R. Gleason (loesljrg@accucom.net) version 6.0 if "`1'" == "?" { which oddsrcii exit } local i 0 while `i' < 4 { local i = `i' + 1 local t : word `i' of a b c d gettoken `t' 0 : 0, parse(" ,") confirm integer number ``t'' if ``t'' < 0 { di in red "Invalid cell frequency: ``t''" error 499 } } syntax [, LEVel(real $S_level) NOTable TABopt(string asis) /* */ NONE ALL AGresti COrnf GArt WOolf] if "`notable'" == "" { if "`tabopt'" == "" { local tabopt "noexact" } else { local z `"di """' } tabi `a' `b' \ `c' `d', `tabopt' `z' } if "`none'" != "" { exit } if `level' < 1 { local level = 100*`level' } local z = invnorm((100+`level')/200) if "`all'" != "" { local A "cornf agresti gart woolf" } else { local A "`cornf' `agresti' `gart' `woolf'" if "`A'" == " " { local A "agresti" } } tokenize `A' while "`1'" != "" { local H 0.0 if "`1'" == "cornf" { local H -2 } else if "`1'" == "agresti" { local H -1 } else if "`1'" == "gart" { local H 0.5 } x `a' `b' `c' `d' `z' `level' `H' mac shift } end program define x, rclass if `7' == -2 { local A "Cornfield" local T = round(`6', 1) qui cci `1' `2' `3' `4', level(`T') local LL = r(lb_or) local UL = r(ub_or) local T = r(or) } else { if `1'*`4' == 0 { local LL 0 } if `2'*`3' == 0 { local UL = . } if `7' == -1 { local A " Agresti" local ab = `1' + `2' local cd = `3' + `4' local ac = `1' + `3' local bd = `2' + `4' local nn = `ab' + `cd' local K = 2/(`nn'*`nn') local k = `nn'/(`nn'+2) local 1 = `k'*(`1' + `ab'*`ac'*`K') local 2 = `k'*(`2' + `ab'*`bd'*`K') local 3 = `k'*(`3' + `ac'*`cd'*`K') local 4 = `k'*(`4' + `bd'*`cd'*`K') } else if `7' == 0 { local A " Woolf" } else if "`7'" == "0.5" { local A " Gart" local 1 = `1' + 0.5 local 2 = `2' + 0.5 local 3 = `3' + 0.5 local 4 = `4' + 0.5 } local T = log((`1'*`4')/(`2'*`3')) local SE = sqrt(1/`1' + 1/`2' + 1/`3' + 1/`4') if "`LL'" == "" { local LL = exp(`T' - `5'*`SE') } if "`UL'" == "" { local UL = exp(`T' + `5'*`SE') } local T = exp(`T') local Add "return add" } di in gr "`A': Odds Ratio =" in ye %7.4g `T' in gr /* */ ", [`6'% CI]: " in ye %7.4g `LL' " " %7.4g `UL' local A : word 1 of `A' local A = substr("`A'", 1, 5) return scalar ub_`A' = `UL' return scalar lb_`A' = `LL' return scalar or_`A' = `T' return scalar level = `6' `Add' end