Announcement

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

  • Fisher exact test

    Hi, I use Stata 12. I'm looking for ways to do 400 different fisher exact tests efficiently. So instead of doing "tabi 12 2\37, exact" 400 times, is there a way i can incorporate the commands in a do file? I have 400 different 2x2 tables, and they're arranged into a big table with 400 rows and 4 columns; each column in a row represents a cell in the 2x2 table. Any help will be greatly appreciated!

  • #2
    May,

    Here's a quick-n-dirty way (assumes your 4 column variables are c1, c2, c3, and c4 and they are all non-missing):

    Code:
    forvalues x=1/`=_N' {
      tabi `=c1[`x']' `=c2[`x']' \  `=c3[`x']' `=c4[`x']' , exact
    }
    Regards,
    Joe

    Comment


    • #3
      Thanks, Joe. One more question. So how can I save the test statistics of the 400 tests into a table? Thanks again.

      May

      Comment


      • #4
        The resulting p-values are in the scalars r(p_exact) and r(p1_exact). So, you could do the following, for example:

        Code:
        gen p=.
        gen p1=.
        forvalues x=1/`=_N' {  
          tabi `=c1[`x']' `=c2[`x']' \  `=c3[`x']' `=c4[`x']' , exact  
          replace p=`r(p_exact)' in `x'  
          replace p1=`r(p1_exact)' in `x'  
         }

        Comment


        • #5
          See also this FAQ for related technique http://www.stata.com/support/faqs/da...iate-commands/

          Comment

          Working...
          X