Skip to Main Content

Stata Teaching Tools:  Odds ratio calculation

Purpose:  The purpose of this program is to calculate
the odds ratio given the probabilities supplied by the user.  The
probability of Y = 1 for up to four levels of a categorical variable may be
given.  This program is useful for illustrating the relationship between
these probabilities, the odds for each group and the odds ratio(s).  The reference (or omitted) category may also be selected.  

Download:  You can download this program from within Stata by
typing search orcalc (see
How can I used the search command to search for programs and get additional
help?
for more information about using search).

Use of program:  To use this program, type orcalc in the
Stata command window.  Up to four numbers may be given, but at least two
are required.  By default, the last group is used as the reference group
(i.e., the omitted group).  This can be changed with the ref(#)
option, where the number specifies the number of the group to be used as the
reference group.

Examples:  The following shows the output from issuing the orcalc
command.  In this example, we assume that one is doing a logistic
regression with a binary outcome variable and a predictor variable that has two
categories.  We assume that the probabilities for the two groups are .3 and
4. 
By default, orcalc uses the last group as the reference (or omitted)
group.  The program shows the formula for calculating the odds ratio, which
is the odds of group 2 divided by the odds of group 1.  To calculate the
odds for group 2, .4 is divided by 1 – .4.  The odds for group 1 is
calculated by dividing .3 by 1 – .3, and the odds ratio, which is the ratio of
the odds for group 2 divided by the odds for group 1, is .667 divided by .429,
or 1.556.

Image orcalccrw1-1

The following shows the output from issuing the orcalc command,
assuming that the predictor variable has three categories whose probabilities
are .3, .4 and .6.  Two odds ratios are calculated, one comparing group 2 to group
1, and one comparing group 3 to group 1.  Again, the last
group is used as the reference group.

Image orcalccrw2-1

This example is the same as the one above, except that we have used the ref(#)
option to use the second group as the
reference group.  You will notice that this greatly changes both odds
ratios.

Image orcalccrw3-1

The following shows the output from issuing the orcalc command,
assuming that the predictor variable has four categories with probabilities of
3, .4, .6 and .7. 
Hence, three odds ratios are calculated, and because the ref(#) option
was not used, the last group is used as the reference group.

Image orcalccrw4-1