Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: calculating Fishers exact test and recording output for multiple two by two tables at once

 From Michael Norman Mitchell To statalist@hsphsun2.harvard.edu Subject Re: st: calculating Fishers exact test and recording output for multiple two by two tables at once Date Mon, 17 May 2010 15:46:29 -0700

```Dear Mike

```
I wonder if this example below will help. It has four columns named a b c and d, corresponding to the four frequencies you describe. I rename them to v1 v2 v3 v4, and reshape them to a long format. I then create the variable -event- and -trt- to correspond to event and treatment, and then use -tab- to create the fishers exact tests, and add -bysort id- to do this separately for each study.
```
I hope this helps.

Michael N. Mitchell
See the Stata tidbit of the week at...
http://www.MichaelNormanMitchell.com

-- snip ---
clear
input id a b c d
1 5 9 3 5
2 1 5 3 7
3 2 9 4 3
end

rename a v1
rename b v2
rename c v3
rename d v4

reshape long v, i(id) j(condition)
generate event = 1 if inlist(condition,1,2)
replace  event = 0 if inlist(condition,3,4)
generate trt   = 1 if inlist(condition,1,3)
replace  trt   = 0 if inlist(condition,2,4)

bysort id: tab event trt [fw=v], exact
-- snip ---

On 2010-05-17 3.22 PM, Michael Walsh wrote:
```
```Hello all,

I would like to calculate a two-sided Fisher's exact test for many studies
in one data set and record the test value in a new column (or file). The
information from the two-by-two table occupies one row for each study (col 1
= treatment events, col 2 = control events, col 3 = treatment non-events,
col 4 = control non-events). Does anyone know of an existing Stata procedure
that can accommodate this?

Thanks for considering,
Mike

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```
```*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```