# Confidence intervals and standard error for binary data/proportions

I'm doing some research into degrees held by professionals of different types, based on survey data. I'd like to be able to provide confidence intervals for some of the subgroups of professionals as they are of variable sample sizes, to work out whether the data is significant. The data is confidential, so i've made up some mock data below to demonstrate.

In the data you can see that 26% of teachers have at least one of the qualifications, 19% of lawyers and 66% of doctors. How do I work out the confidence intervals for this data?

I'm working in stata, and the information is stored as a person by person basis, with a 0 if they don't have a degree, and a 1 if they have one, so I worked out the percentage by adding up and dividing from the total, just can't work out how you get a CI. (does it require SE and SD?)

• Teachers n=115
• PhD :3
• Masters :5
• Diploma :22
• Any of the above qualifications :30
• Lawyers n=220
• PhD :4
• Masters :15
• Diploma :23
• Any of the above qualifications :42
• Doctors n=15
• PhD :3
• Masters :6
• Diploma :1
• Any of the above qualifications :10

There are at least three different ways of doing this:

/* (1) Just Using Counts */
cii proportion 15 10, jeffreys
cii proportion 220 42, jeffreys
cii proportion 115 30, jeffreys

/* (2) Using The Variables */
/* Fake Data */
clear
input total_n str10 occupation q1
115 "teachers" 30
220 "lawyers" 42
15  "doctors" 10
end
gen q0 = total_n - q1
drop total_n
reshape long q, i(occupation) j(any_quals)
expand q
drop q
sort occupation any_quals
sencode occupation, replace
tab occupation any_quals, row chi2
bys occupation: ci proportion any_quals, jeffreys

/* (3) Using a probit/logit: helpful for comparing groups */
quietly probit any_quals i.occupation
margins occupation
margins ar.occupation
margins r.occupation


Here I used the Jeffreys binomial confidence intervals since the doctors group has such a small sample size, but you could have also used Wilson or Agresti–Coull intervals. You can read more about these in the Stata manuals. Examples 6 and 7 go into this a bit and provide a reference.

The probit/logit CIs won't exactly match the binomial CIs, but they will allow you to test a richer set of hypotheses.