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

st: Tabodds with multiple explanatory variables


From   "Hulley, Benjamin (NIH/NCI)" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: Tabodds with multiple explanatory variables
Date   Tue, 17 Aug 2004 17:31:17 -0400

Howdy,

This is mostly a post to ask, is there an easier/more elegant way?

I would like to calculate odds ratios over pairs of stratification
variables, for example, hair and eyes.  Hair has values of 0 or 1 and eyes
can be 0, 1, or 2.  There are then 6 categories: hair = 0 and eyes = 0; hair
= 1 and eyes = 0; hair = 0 and eyes = 1; hair = 1 and eyes = 1 ...and so on.
The goal is a table that looks like this:

---------------------------------------------------------------------------
   hair eyes |  Odds Ratio       chi2       P>chi2     [95% Conf. Interval]
-------------+----------------------------------------------------------
     0     0 |    1.000000          .           .              .          .
     1     0 |    0.857143       0.02       0.8814      0.112836   6.511180
     0     1 |    3.529412       2.23       0.1354      0.602837  20.663549
     1     1 |    3.600000       2.39       0.1222      0.633331  20.463229
     0     2 |   44.000000      16.95       0.0000      2.009823 963.268843
     1     2 |    6.857143       4.72       0.0298      0.911312  51.596417
---------------------------------------------------------------------------

To achieve this result I currently use the following code: 
 
gen cat = hair + 2*eyes
lab def catlbl 0 "0   0" 1 "1   0" 2 "0   1" 3 "1   1" 4 "0   2" 5 "1   2"
lab val cat catlbl
lab var cat "hair eyes"
tabodds cases cat, or base(1) // make sure we use hair = 0, eyes = 0 as the
referent

This code works but isn't portable.  I have 3 primary variables to be
stratified over 8 other variables all with various possible values (ie some
are 0,1, and others are 0,1,2,3) yielding 24 combinations.  Is there a
clever, portable way to generate variables representing all possible
combinations of two categorical variables?  Or, better yet, a way to get
tabodds to stratify over two variables?

Thanks in advance to any thought given this problem,

Ben Hulley

*******************
NCI/DCEG/GEB
Room: EPS 7007
Tel: (301) 402-1622
Fax: (301) 402-4489
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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