Introduction
Let’s say you have a hypothesis about an experiment that has only two possible outcomes, which you can code as 0 and 1. In Stata, you can easily identify the mean and 95% confidence interval (CI) of any binomial distribution. In this blog entry, we’ll show you how.
Generate Data
Let’s say that you polled 111 people on whether they would support the passage of a particular law, with support = 1 and opposition = 0. First, let’s create a dataset that reflects this experiment, and let’s add the gender of participants to demonstrate how Stata can subset binomial confidence intervals.
set obs 111
gen a_sup = runiform(0,1)
gen sup = round(a_sup)
label variable sup "Support"
label define sup 0 "Rejects" 1 "Supports"
label value sup sup
gen a_gender = runiform(0,1)
gen gender = round(a_gender)
label variable gender "Gender"
label define gender 0 "Male" 1 "Female"
label value gender gender
drop a*
codebook
Generate the Binomial CI
Now try the following code:
ci proportions sup
Here’s what you get:
So the proportion of people supporting the law is around 51.4%, and the 95% CI is around 41.7% to 61%. If you wanted, you could change the confidence level to 90% by trying:
ci proportions sup, level(90)
The confidence interval now becomes:
Let’s say you wanted to generate separate confidence intervals for men and women. Try the following code:
by gender, sort: ci proportions sup
Here’s what you get:
By the substantial overlap in CIs, you can infer that there is no statistically significant difference between male and female agreement with the law, but you might want to run a logistic regression with odds ratio reporting in order to confirm this intuition with a p value.
BridgeText can help you with all of your statistical analysis needs.