Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: calculating Fishers exact test and recording output for multiple two by two tables at once
From
Phil Schumm <[email protected]>
To
[email protected]
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 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?
Perhaps the easiest way to do this is with -statsby-. For example,
suppose that the two variables that comprise your two-by-two
table(s) are called var1 and var2, and suppose that your studies are
indexed by a variable called study. In that case, the following
will place the p-value and the cell frequencies into individual
variables -- 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)
Sorry, I read too fast -- it appears that you've already collapsed the
data into cell frequencies (the command above is for the situation
where you haven't collapsed the data yet). However, you can use -
statsby- in this case too. For example, suppose your frequency counts
are in the variables r1c1, r1c2, r2c1 and r2c2, and your studies are
still indexed by the variable study (one distinct value per
observation). In that case, you may use the following:
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] ///
r2c1=mymat[2,1] r2c2=mymat[2,2], by(study)
clear: ///
tab row column [fw=r], exact matcell(mymat)
Of course, there are other ways to do this, as other posters have
indicated. However, -statsby- is often worth considering as the
cleanest -- if not the easiest -- way to handle such things.
-- 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/