Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • sample size for sensitivity/specificity studies?

    How can I calculate the sample size for sensitivity/specificity studies using STATA?

  • #2
    I'm not sure what you mean by sensitivity/specificity studies, but why wouldn't you approach power analysis and sample size estimation in the same manner for them as you would for any other type of study?

    Comment


    • #3
      Thanks Joseph. THis makes sense.

      Comment


      • #4
        I have a question concerning how to combine two categorical variables in Stata:
        Let's say variable A (1=no; 2=yes) and variable B ((1=no; 2=yes)
        I did the following, but it did not correctly combine the two variables:
        Generate AB= A &B
        replace AB=0
        • replace AB = 1 if A==1 & B==1
        • replace AB = 2 if A==2 & B==2

        Comment


        • #5
          Hi Sonia,

          The syntax gen newvar = var1 & var2 works. It does combine variables in a consistent manner - it might not be what you expected, but this does not mean it did not correctly combine both variables.

          The issue most likely is related to how your variables are coded. As far as I can tell, using the & operator in such situations makes Stata look for zero and non zeros. The code below exemplifies it:

          Code:
          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
          In short, the command works. I don't know how you want your variable to be, because you did not specify it. But I would try:

          Code:
          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.
          Is this what you want? If not, please specify. Note that the replace commands you issued does not account for situations when A==1 and B==2 (or vice-versa).

          Comment

          Working...
          X