program drop _all program define hetero version 12.1 args rrr1 lcl1 ucl1 rrr2 lcl2 ucl2 *first RRR disp as text "First RRR (95% CI): " as result %4.2f `rrr1' " (" /// %4.2f `lcl1' ", " %4.2f `ucl1' ")" *second RRR disp as text "Second RRR (95% CI): " as result %4.2f `rrr2' " (" /// %4.2f `lcl2' ", " %4.2f `ucl2' ")" *variances local var1 = ((ln(`ucl1')-ln(`rrr1'))/invnormal(0.975))^2 local var2 = ((ln(`ucl2')-ln(`rrr2'))/invnormal(0.975))^2 * pooled estimate local num_pool = ((ln(`rrr1')/`var1') + (ln(`rrr2')/`var2')) local denom_pool = ((1/`var1') + (1/`var2')) local pooled = `num_pool' / `denom_pool' disp as text "Pooled RRR= ", as result %4.2f exp(`pooled') * cochran's Q local q = (((ln(`rrr1')-`pooled')^2)/`var1') + (((ln(`rrr2')-`pooled')^2)/`var2') disp as text "Cochran's Q = ", as result %4.2f `q' as text " p-value = ", /// as result %5.4f chi2tail(1, `q') * altman disp " " disp " " disp as text "Altman test for interaction" disp " " local drrr = ln(`rrr1') - ln(`rrr2') disp as text "Diff in log RRRs: ", as result %5.3f `drrr' local serrr1 = (ln(`lcl1') - ln(`ucl1')) / (2*invnormal(0.975)) local serrr2 = (ln(`lcl2') - ln(`ucl2')) / (2*invnormal(0.975)) local se_drrr = sqrt((`serrr1'*`serrr1' + `serrr2'*`serrr2')) disp as text "95% CI for diff: " as result "(" %4.3f `drrr'-(invnormal(0.975)*`se_drrr') ", " /// %4.3f `drrr'+(invnormal(0.975)*`se_drrr') ")" disp as text "Test of interaction: " as result "z = " %5.3f `drrr'/`se_drrr' /// " p = " %5.4f 2*(1-(normal(abs(`drrr'/`se_drrr')))) disp as text "Ratio of estimates, 95% CI: " as result %4.2f exp(`drrr') " (" /// %4.2f exp(`drrr'-invnormal(0.975)*`se_drrr') ", " %4.2f exp(`drrr'+invnormal(0.975)*`se_drrr') ")" end