## Stata 15 help for prtest

```
[R] prtest -- Tests of proportions

Syntax

One-sample test of proportion

prtest varname == #p [if] [in] [, onesampleopts]

Two-sample test of proportions using groups

prtest varname [if] [in] , by(groupvar) [twosamplegropts]

Two-sample test of proportions using variables

prtest varname1 == varname2 [if] [in] [, level(#)]

Immediate form of one-sample test of proportion

prtesti #obs1 #p1 #p2 [, level(#) count]

Immediate form of two-sample test of proportions

prtesti #obs1 #p1 #obs2 #p2 [, level(#) count]

onesampleopts         Description
-------------------------------------------------------------------------
Main
level(#)            confidence level; default is level(95)
cluster(varname)    variable defining the clusters
rho(#)              intraclass correlation
-------------------------------------------------------------------------

twosamplegropts       Description
-------------------------------------------------------------------------
Main
* by(groupvar)        variable defining the groups
level(#)            confidence level; default is level(95)
cluster(varname)    variable defining the clusters
rho(#)              common intraclass correlation
rho1(#)             intraclass correlation for group 1
rho2(#)             intraclass correlation for group 2
-------------------------------------------------------------------------
* by(groupvar) is required.

by is allowed with prtest; see [D] by.

prtest

Statistics > Summaries, tables, and tests > Classical tests of
hypotheses > Proportion test

prtesti

Statistics > Summaries, tables, and tests > Classical tests of
hypotheses > Proportion test calculator

Description

prtest performs tests on the equality of proportions using large-sample
statistics.  The test can be performed for one sample against a
hypothesized population value or for no difference in population
proportions estimated from two samples.  Clustered data are supported.

prtesti is the immediate form of prtest; see immed.

Options for prtest

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

by(groupvar) specifies a numeric variable that contains the group
information for a given observation.  This variable must have only
two values.  Do not confuse the by() option with the by prefix; both
may be specified.

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

cluster(varname) specifies the variable that identifies clusters.  The
cluster() option is required to adjust the computation for
clustering.

rho(#) specifies the intraclass correlation for a one-sample test or the
common intraclass correlation for a two-sample test.  The rho()
option is required to adjust the computation for clustering for a
one-sample test.

rho1(#) specifies the intraclass correlation of the first group for a
two-sample test using groups.  The rho() option or both rho1() and
rho2() options are required to adjust the computation for clustering.

rho2(#) specifies the intraclass correlation of the second group for a
two-sample test using groups.  The rho() option or both rho1() and
rho2() options are required to adjust the computation for clustering.

Options for prtesti

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

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

count specifies that integer counts instead of proportions be used in the
immediate forms of prtest.  In the first syntax, prtesti expects that
#obs1 and #p1 are counts -- #p1 < #obs1 -- and #p2 is a proportion.
In the second syntax, prtesti expects that all four numbers are
integer counts, that #obs1 > #p1, and that #obs2 > #p2.

Remarks

For one-sample tests of proportions with small sample sizes and to obtain
exact p-values, researchers should use bitest.

Examples

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

One-sample test of proportion
. prtest foreign==.4

One-sample test of proportion adjusted for clustering with clusters
defined by rep78 and with an intraclass correlation of 0.4
. prtest foreign==.4, cluster(rep78) rho(0.4)

---------------------------------------------------------------------------
Setup
. webuse cure

Two-sample test of proportions using variables
. prtest cure1==cure2

---------------------------------------------------------------------------
Setup
. webuse cure2

Two-sample test that cure has same proportion for males and females
. prtest cure, by(sex)

----------------------------------------------------------------------------
Setup
. webuse pneumoniacrt

Two-sample test that pneumonia has same proportion for two vaccine
groups, adjusted for clustering with clusters defined by cluster and
with a common intraclass correlation of 0.02
. prtest pneumonia, by(vaccine) cluster(cluster) rho(0.02)

---------------------------------------------------------------------------
Immediate form of one-sample test of proportion
. prtesti 50 .52 .70

First two numbers are counts
. prtesti 30 4 .7, count

Immediate form of two-sample test of proportions
. prtesti 30 .4 45 .67

All numbers are counts
. prtesti 30 4 45 17, count

---------------------------------------------------------------------------

Stored results

One-sample prtest and prtesti store the following in r():

Scalars
r(N)                sample size
r(P)                sample proportion
r(se)               standard error of sample proportion
r(lb)               lower confidence bound of sample proportion
r(ub)               upper confidence bound of sample proportion
r(z)                z statistic
r(p_l)              lower one-sided p-value
r(p)                two-sided p-value
r(p_u)              upper one-sided p-value
r(level)            confidence level

Cluster-adjusted one-sample prtest also stores the following in r():

Scalars
r(K)                number of clusters K
r(M)                cluster size M
r(rho)              intraclass correlation
r(CV_cluster)       coefficient of variation for cluster sizes

Two-sample prtest and two-sample prtesti store the following in r():

Scalars
r(N1)               sample size of population one
r(N2)               sample size of population two
r(P1)               sample proportion for population one
r(P2)               sample proportion for population two
r(P_diff)           difference of proportions
r(se1)              standard error of population-one sample proportion
r(se2)              standard error of population-two sample proportion
r(se_diff)          standard error of the difference of proportions
r(se_diff0)         standard error of the difference of proportions
under H_0
r(lb1)              lower confidence bound of population-one sample
proportion
r(ub1)              upper confidence bound of population-one sample
proportion
r(lb2)              lower confidence bound of population-two sample
proportion
r(ub2)              upper confidence bound of population-two sample
proportion
r(lb_diff)          lower confidence bound of the difference of
proportions
r(ub_diff)          upper confidence bound of the difference of
proportions
r(z)                z statistic
r(p_l)              lower one-sided p-value
r(p)                two-sided p-value
r(p_u)              upper one-sided p-value
r(level)            confidence level

Cluster-adjusted two-sample prtest using the by() option also stores the
following in r():

Scalars
r(K1)               population-one number of clusters K_1
r(K2)               population-two number of clusters K_2
r(M1)               population-one cluster size M_1
r(M2)               population-two cluster size M_2
r(rho)              common intraclass correlation
r(rho1)             population-one intraclass correlation
r(rho2)             population-two intraclass correlation
r(CV_cluster1)      population-one coefficient of variation for cluster
sizes
r(CV_cluster2)      population-two coefficient of variation for cluster
sizes

```