Home  /  Resources & Support  /  Introduction to Stata basics  /  Odds-ratio calculator

Sometimes, we are given summary data and asked to estimate the odds ratio and its confidence interval. This is common with case–control studies where a sample of cases and controls are selected from a population and exposure to different risk factors is ascertained retrospectively.

For example, we might be asked to estimate the odds ratio for 12 exposed and 16 unexposed among case subjects and 55 exposed and 125 unexposed among control subjects. We can do this using Stata's cci command command followed by four numbers:

The number of exposed cases (12)
The number of unexposed cases (16)
The number of exposed noncases (55)
The number of unexposed noncases (125)

. cci 12 16 55 125

Proportion
Exposed Unexposed Total exposed
Cases 12 16 28 0.4286
Controls 55 125 180 0.3056
Total 67 141 208 0.3221
Point estimate [95% conf. interval]
Odds ratio 1.704545 .6848212 4.125435 (exact)
Attr. frac. ex. .4133333 -.4602353 .7576013 (exact)
Attr. frac. pop .1771429
chi2(1) = 1.68 Pr>chi2 = 0.1950

The output gives us a lot of information.

The odds ratio is the odds of being a case in the exposed group divided by the odds of being a case in the unexposed group. Here the odds ratio and 95% confidence interval is 1.70 (0.68 - 4.13).

The attributable fraction among the exposed (AFE) is an estimate of the proportion of exposed cases attributable to exposure. Here the AFE and 95% confidence interval is 0.41 (-0.46 - 0.76). The AFE will be labeled preventated fraction among the exposed (PFE) when the odds ratio is less than one.

The attributable fraction for the population (AFP) is the net proportion of all cases attributable to exposure. Here the AFP is 0.18. The PFP will be labeled prevented fraction for the population (AFP) when the odds ratio is less than one.

Note that the estimates of the AFE and PFE may be different for the cci command and the csi command. The reported value of the AFE or PFE for cci is calculated using the odds ratio as a proxy for the risk ratio. This can be justified only if the outcome is rare in the population. The extrapolation to the AFP or PFP assumes that the control group is a random sample of the corresponding group in the underlying population.

The \(x^2\)statistic at the bottom of the table tests for an association between exposure status and case status. Here the one degree-of-freedom \(x^2\)statistic equals 1.68 with a p-value of 0.1950.

It is often appropriate to use the exact option for small sample sizes. This will report 1-sided and 2-sided p-values for Fisher's exact tests.

. cci 12 16 55 125, exact

Proportion
Exposed Unexposed Total exposed
Cases 12 16 28 0.4286
Controls 55 125 180 0.3056
Total 67 141 208 0.3221
Point estimate [95% conf. interval]
Odds ratio 1.704545 .6848212 4.125435 (exact)
Attr. frac. ex. .4133333 -.4602353 .7576013 (exact)
Attr. frac. pop .1771429
1-sided Fisher's exact P = 0.1408 2-sided Fisher's exact P = 0.1997

By default, cci estimates exact confidence intervals. You can use the woolf and cornfield options to report the Woolf and Cornfield approximations for the confidence intervals, respectively.

. cci 12 16 55 125, woolf

Proportion
Exposed Unexposed Total exposed
Cases 12 16 28 0.4286
Controls 55 125 180 0.3056
Total 67 141 208 0.3221
Point estimate [95% conf. interval]
Odds ratio 1.704545 .756093 3.842748 (Woolf)
Attr. frac. ex. .4133333 -.3225886 .7397696 (Woolf)
Attr. frac. pop .1771429
chi2(1) = 1.68 Pr>chi2 = 0.1950 . cci 12 16 55 125, cornfield
Proportion
Exposed Unexposed Total exposed
Cases 12 16 28 0.4286
Controls 55 125 180 0.3056
Total 67 141 208 0.3221
Point estimate [95% conf. interval]
Odds ratio 1.704545 .7670751 3.793285 (Cornfield)
Attr. frac. ex. .4133333 -.3036533 .7363763 (Cornfield)
Attr. frac. pop .1771429
chi2(1) = 1.68 Pr>chi2 = 0.1950

You can watch a demonstration of these commands by clicking on the link to the YouTube video below. You can read more about these commands by clicking on the links to the Stata manual entries below.