__Title__

**[R] ci** -- Confidence intervals for means, proportions, and counts (syntax
prior to version 14.1)

*[The syntax of ***ci*** and ***cii*** was changed as of version 14.1.*
*This help file documents **ci**'s and **cii**'s old syntax and as*
*such is probably of no interest to you. If you have set *
version* to less than 14.1 in your old do-files, you do not*
*have to translate **ci**s or **cii**s to modern syntax. This help*
*file is provided for those wishing to debug or understand*
*old code. Click **here** for the help file of the modern **ci*
*and **cii** commands.]*

__Syntax__

Syntax for ci

**ci** [*varlist*] [*if*] [*in*] [*weight*] [**,** *options*]

Immediate command for variable distributed as normal

**cii** *#obs* *#mean* *#sd* [**,** *ciin_option*]

Immediate command for variable distributed as binomial

**cii** *#obs* *#succ* [**,** *ciib_options*]

Immediate command for variable distributed as Poisson

**cii** *#exposure* *#events* **,** __p__**oisson** [*ciip_options*]

*#succ* and *#events* must be an integer or between 0 and 1. If the number
is between 0 and 1, Stata interprets it as the fraction of successes
or events and converts it to an integer number representing the
number of successes or events. The computation then proceeds as if
two integers had been specified.

*options* Description
-------------------------------------------------------------------------
Main
__b__**inomial** binomial 0/1 variables; compute exact confidence
intervals
__p__**oisson** Poisson variables; compute exact confidence
intervals
__exp__**osure(***varname***)** exposure variable; implies **poisson**
__exa__**ct** calculate exact confidence intervals; the default
__wa__**ld** calculate Wald confidence intervals
__w__**ilson** calculate Wilson confidence intervals
__a__**gresti** calculate Agresti-Coull confidence intervals
__j__**effreys** calculate Jeffreys confidence intervals
__t__**otal** add output for all groups combined (for use with
**by** only)
__sep__**arator(***#***)** draw separator line after every *#* variables;
default is **separator(5)**
__l__**evel(***#***)** set confidence level; default is **level(95)**
-------------------------------------------------------------------------
**by** and **statsby** are allowed with **ci**; see prefix.
**aweight**s and **fweight**s are allowed, but **aweight**s may not be specified with
the **binomial** or **poisson** option, see weight.

*ciin_option* Description
-------------------------------------------------------------------------
__l__**evel(***#***)** set confidence level; default is **level(95)**
-------------------------------------------------------------------------

*ciib_options* Description
-------------------------------------------------------------------------
__l__**evel(***#***)** set confidence level; default is **level(95)**
__exa__**ct** calculate exact confidence intervals; the default
__wa__**ld** calculate Wald confidence intervals
__w__**ilson** calculate Wilson confidence intervals
__a__**gresti** calculate Agresti-Coull confidence intervals
__j__**effreys** calculate Jeffreys confidence intervals
-------------------------------------------------------------------------

*ciip_options* Description
-------------------------------------------------------------------------
* __p__**oisson** numbers are Poisson-distributed counts
__l__**evel(***#***)** set confidence level; default is **level(95)**
-------------------------------------------------------------------------
* **poisson** is required.

__Menu__

__ci__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Confidence intervals**

__cii for variable distributed as normal__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Normal CI calculator**

__cii for variable distributed as binomial__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Binomial CI calculator**

__cii for variable distributed as Poisson__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Poisson CI calculator**

__Description__

**ci** computes standard errors and confidence intervals for each of the
variables in *varlist*. Normal confidence intervals are produced by
default. However, a variety of binomial confidence intervals or exact
Poisson confidence intervals can be requested.

**cii** is the immediate form of **ci**; see immed for a general discussion of
immediate commands.

__Options__

+------+
----+ Main +-------------------------------------------------------------

**binomial** tells **ci** that the variables are 0/1 variables and that binomial
confidence intervals will be calculated. (**cii** produces binomial
confidence intervals when only two numbers are specified.)

**poisson** specifies that the variables (or numbers for **cii**) are
Poisson-distributed counts; exact Poisson confidence intervals will
be calculated.

**exposure(***varname***)** is used only with **poisson**. You do not need to specify
**poisson** if you specify **exposure()**; **poisson** is assumed. *varname*
contains the total exposure (typically a time or an area) during
which the number of events recorded in *varlist* were observed.

**exact**, **wald**, **wilson**, **agresti**, and **jeffreys** specify that variables are 0/1
and specify how binomial confidence intervals are to be calculated.

**exact** is the default and specifies exact (also known in the
literature as Clopper-Pearson [1934]) binomial confidence intervals.

**wald** specifies calculation of Wald confidence intervals.

**wilson** specifies calculation of Wilson confidence intervals.

**agresti** specifies calculation of Agresti-Coull confidence intervals.

**jeffreys** specifies calculation of Jeffreys confidence intervals.

See Brown, Cai, and DasGupta (2001) for a discussion and comparison
of the different binomial confidence intervals.

**total** is for use with the **by** prefix. It requests that, in addition to
output for each by-group, output be added for all groups combined.

**separator(***#***)** specifies how often separation lines should be inserted into
the output. The default is **separator(5)**, meaning that a line is
drawn after every five variables. **separator(10)** would draw the line
after every 10 variables. **separator(0)** suppresses the separation
line.

**level(***#***)** specifies the confidence level, as a percentage, for confidence
intervals. The default is **level(95)** or as set by **set level**.

__Examples__

---------------------------------------------------------------------------
Setup
**. sysuse auto**

Obtain normal-approximation 90% confidence intervals for means of
normally distributed variables
**. ci mpg price, level(90)**

---------------------------------------------------------------------------
Setup
**. webuse promonone**

Obtain various binomial confidence intervals for proportions
**. ci promoted, binomial**
**. ci promoted, binomial wilson**
**. ci promoted, binomial agresti**
**. ci promoted, binomial jeffreys**

---------------------------------------------------------------------------
Setup
**. webuse petri**

Obtain exact Poisson confidence interval for a count variable
**. ci count, poisson**

---------------------------------------------------------------------------
Setup
**. webuse rm**

Obtain confidence intervals for total exposure variables
**. ci deaths, exposure(pyears)**

Obtain confidence intervals for mean for data with 166 observations,
mean=19509, and sd=4379
**. cii 166 19509 4379**

Same as above, but obtain 90% confidence intervals
**. cii 166 19509 4379, level(90)**

Obtain binomial confidence intervals for data with 10 binomial events and
1 observed success
**. cii 10 1**

Same as above, but obtain the Wilson confidence interval
**. cii 10 1, wilson**

Obtain Poisson confidence intervals for data with 1 exposure and 27
events
**. cii 1 27, poisson**
---------------------------------------------------------------------------

__Video examples__

Immediate commands in Stata: Confidence intervals for Poisson data

Immediate commands in Stata: Confidence intervals for binomial data

Immediate commands in Stata: Confidence intervals for normal data

__Stored results__

**ci** and **cii** store the following in **r()**:

Scalars
**r(N)** number of observations or exposure
**r(mean)** mean
**r(se)** estimate of standard error
**r(lb)** lower bound of confidence interval
**r(ub)** upper bound of confidence interval

__References__

Brown, L. D., T. T. Cai, and A. DasGupta. 2001. Interval estimation for
a binomial proportion. *Statistical Science* 16: 101-133.

Clopper, C. J., and E. S. Pearson. 1934. The use of confidence or
fiducial limits illustrated in the case of the binomial. *Biometrika*
26: 404-413.