How can I calculate the sample size for sensitivity/specificity studies using STATA?
-
Login or Register
- Log in with
clear set obs 100 gen try1 = runiform() gen try2 = runiform() replace try1 = 1 if try1 >= 0.5 replace try1 = 0 if try1 < 0.5 replace try2 = 1 if try2 >= 0.5 replace try2 = 0 if try2 < 0.5 gen try12 = try1 & try2 *Your variables are coded 0 and non-zero (in this case, 1), Stata assigns 1 to the newvar (try12) when both are non-zero, and 0 when at least one of them is 0. tab try1 try2 tab try12 gen try3 = runiform() gen try4 = runiform() replace try3 = 1 if try3 >= 0.5 replace try3 = 2 if try3 < 0.5 replace try4 = 1 if try4 >= 0.5 replace try4 = 2 if try4 < 0.5 gen try34 = try3 & try4 *Your variables are both coded as non-zero values (in this case, 1 and 2, as your dataset), Stata only assigns 0 when when at least one of them is 0. Since none of the original vars have 0 as a code, Stata assign all observations as 1. This is not wrong - Stata is looking for zeros! tab try3 try4 tab try34 *What if I code using 0 and values other than 1? gen try5 = runiform() gen try6 = runiform() replace try5 = 2 if try5 >= 0.5 replace try5 = 0 if try5 < 0.5 replace try6 = 2 if try6 >= 0.5 replace try6 = 0 if try6 < 0.5 gen try56 = try5 & try6 *Your variables are coded 0 and non-zero (in this case, 2), Stata assigns 1 to the newvar (try12) when both are non-zero, and 0 when at least one of them is 0. tab try5 try6 tab try56
recode A 1=0 2=1 // 0 now means No, 1 means Yes recode B 1=0 2=1 // 0 now means No, 1 means Yes generate AB = A & B // this will make all your 1 and 1 = 1, and all other combinations (1 and 0, 0 and 1, 0 and 0) = 0.
Comment