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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Phil Schumm <pschumm@uchicago.edu> |

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 18:37:41 -0500 |

On May 17, 2010, at 6:12 PM, Phil Schumm wrote:

On May 17, 2010, at 5:22 PM, Michael Walsh wrote:I would like to calculate a two-sided Fisher's exact test for manystudies in one data set and record the test value in a new column(or file). The information from the two-by-two table occupies onerow for each study (col 1 = treatment events, col 2 = controlevents, col 3 = treatment non-events, col 4 = control non-events).Does anyone know of an existing Stata procedure that canaccommodate this?Perhaps the easiest way to do this is with -statsby-. For example,suppose that the two variables that comprise your two-by-twotable(s) are called var1 and var2, and suppose that your studies areindexed by a variable called study. In that case, the followingwill place the p-value and the cell frequencies into individualvariables -- one observation per study:statsby p=r(p_exact) r1c1=mymat[1,1] r1c2=mymat[1,2] ///r2c1=mymat[2,1] r2c2=mymat[2,2],by(study): ///tab var1 var2, exact matcell(mymat)

reshape long r1 r2, i(study) j(column) string reshape long r, i(study colum) j(row) statsby p=r(p_exact) r1c1=mymat[1,1] r1c2=mymat[1,2] ///

tab row column [fw=r], exact matcell(mymat)

-- Phil * * 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/

**References**:**st: calculating Fishers exact test and recording output for multiple two by two tables at once***From:*"Michael Walsh" <mwwalsh@ucalgary.ca>

**Re: st: calculating Fishers exact test and recording output for multiple two by two tables at once***From:*Phil Schumm <pschumm@uchicago.edu>

- Prev by Date:
**st: ivprobit marginal effects** - Next by Date:
**st: read dbf files directly into Stata?** - Previous by thread:
**Re: st: calculating Fishers exact test and recording output for multiple two by two tables at once** - Next by thread:
**AW: st: calculating Fishers exact test and recording output for multiple two by two tables at once** - Index(es):