Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Chi square test

From   May Boggess <[email protected]>
To   [email protected]
Subject   Re: st: Chi square test
Date   25 Jan 2005 12:12:49 -0600

On Tuesday, Peter wrote:
> I am running a stata file to find the odds ratio for the outcome against the
> risk. The problem is I get 2 different chi-squares when I use -tabodds-
> command and -tab- command accompanied with -chi-  at the end to request for
> the chi-square results. Anyone who knows what is going on here?

-tabulate, chi2- is performing the well-known Pearson chi-squared test
of independence of the rows and columns of a two-way table. A reference
for this is Agresti's "Categorical Data Analysis", second edition, page

-tabodds- is performing a score test of the homogeneity of odds.
For two levels of exposure (ie. exposed and unexposed), this test is
described in Clayton and Hills "Statistical Models in
Epidemiology" (1993) page 171. The formula in the Stata manual 
[ST] epitab, page 68, is an extension of the Clayton and Hills formula
to multiple levels of exposure (by which I mean, in the case where k=2,
our formula reduces to that given for U^2/V in Clayton and Hills).

Here is an example for -tabodds-:

 webuse  bdesop
 keep  case alcohol freq
 drop if freq==0
 expand freq
 tabodds case alcohol
 di "chi2= " r(chi2_hom)
 sort alcohol case
 by alcohol : gen N=_N
 by alcohol : replace N=0 if _n!=_N
 by alcohol case: gen a=_N
 gen double e=200*N/975
 replace e=(a-e)^2/N 
 list N a e if e!=.
 replace e=sum(e) 
 di "chi2 ="  e[_N] * 975*(975-1)/(200*775) 
 tabulate case alcohol 

 [email protected]

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index