{smcl}
{hline}
help for {hi:brrtab}
{hline}

{title:Two-way tables for survey data, with balance repeated replication (BRR) based standard errors}

{p 4 11}{cmd:brrtab} {it:varname1} {it:varname2} [{it:weight}]
	[{cmd:if} {it:exp}] [{cmd:in} {it:range}] [ {cmd:,}

{p 4 4}[survey design options]

{p 11 11}{cmdab:brrw:eight(}{it:varlist}{cmd:)} 
    {cmdab:fay(}{it:#}{cmd:)}
    {cmdab:dof(}{it:#}{cmd:)}

{p 4 4}[tabulate options]

{p 11 11}{cmd:tab(}{it:varname}{cmd:)} {cmdab:miss:ing}

{p 4 4}[display items]

{p 11 11}{cmdab:cel:l} {cmdab:cou:nt} {cmd:row} {cmdab:col:umn} {cmd:obs}
    {cmd:se} {cmd:ci} {cmd:deff} {cmd:deft}

{p 4 4}[display options]

{p 11 11}[ {cmdab:prop:ortion} | {cmdab:per:cent} ] {cmdab:nolab:el}
    {cmdab:nomarg:inals} {cmdab:for:mat(%}{it:fmt}{cmd:)} {cmdab:vert:ical}
    {cmdab:l:evel(}{it:#}{cmd:)}

{p 4 4}[statistic options]

{p 11 11}{cmdab:pea:rson} {cmd:lr} {cmdab:nul:l} {cmd:wald} {cmd:llwald}
    {cmdab:noadj:ust} ]


{p}{cmd:pweight}s are allowed; see help {help weights}.  They may be specified
with the command, or by the {help svyset:svyset pweight} command.

{p}A set of replicate weights are required.  They may be specified through
the {cmd:brrweight} option; they need not be respecified for subsequent brr-based commands.

{p}{cmd:brrtab} typed without arguments redisplays previous results.  Any of
the "display items", "display options", or "statistic options" can be
specified when redisplaying with the following exception: {cmd:wald} must be
specified at run time.


{title:Description}

{p}{cmd:brrmodel} produces two-way tabulations with tests for independence for
complex survey data.  The method of balanced repeated replication (BRR) is
used, in conjunction with a set of user-specified replicate weights, to
estimate (co)variances of estimates.  This is an alternate method to
the Taylor series linearization methods used by Stata's {help svy:svy-based} commands.

{p}Except for the different method of variance calculation, {cmd:brrtab}
has identical syntax as {help svytab}.  Point estimates are the same 
as those from svytab; standard errors and tests of independence are different.

{p}{strong}This is a beta test version of the command.{text}  As far as I know, everything
works as it should, but use at your own risk.  Currently, finite population correction 
factors (FPC) are not supported.


{title:Options unique to brrweight}

{p 0 4}{cmd:brrweight()} specifies the list of variables that contain the replicate weights
for the dataset.  The standard errors for the model are based on the variation in 
the estimates generated across the various weights.

{p 4 4}A set of {cmd:brrweights} is required for the analysis.  Once the brrweights are specified
they are stored as a {help char:characteristic} of the dataset and need not be respecified 
in subsequent commands.

{p 0 4}{cmd:fay()} specifies the k value that should be used for weighting the estimates, based
on Fay's method.  The default is zero, meaning that simple averaging will be used.  As with the replicate weights,
the value for fay() is stored as a characteristic of the dataset once it is specified, and need not be
re-specified in subsequent commands.

{p 0 4}{cmd:dof()} specifies the degrees of freedom for the analysis.  By default, it is
equal to the number of replications.


{title:Examples}

{p 8 45}{inp:. brrtab agegrp gender [pw=wgt] , brrw(brrw*)}{p_end}
{p 8 45}{inp:. brrtab, se ci deff} {space 15} [redisplay std. err., etc.]{p_end}
{p 8 45}{inp:. brrtab, count column obs} {space 9} [redisplay counts, etc.]

{p 8 45}{inp:. brrtab agegrp gender, count se} {space 3} [compute std. err. of counts]{p_end}
{p 8 45}{inp:. brrtab, count ci} {space 17} [redisplay CI of counts]

{p 8 45}{inp:. brrtab agegrp gender, wald} {space 7} [compute Wald test]{p_end}
{p 8 45}{inp:. brrtab, pearson lr} {space 15} [redisplay {hi:pearson} and {hi:lr} tests]

{p 8 45}{inp:. brrtab agegrp gender, {bind:tab(income) }} [gives income proportions by {hi:agegrp} and {hi:gender}]


{title:Saved Results}

{cmd:brrtab} generates the same saved results as {cmd:svytab}.

Note that e(cmd) is set to "svytab" in order to allow post-tabulation tests to function correctly.


{title:Methods and formulae}

{p}Point estimates are calculated using aweights, and are identical to those produced by Stata's svytab.
The (co)variance matrix of the estimates is formed by calculating

                   G    
		V = c * SUM [ (B - B(i))(B - B(i))' ]
                  i=1

{p}where B a vector of the estimated cell contents based on the full sample weights, B(i) is the estimated vector using 
the i'th set of replicate weights, G is the number of replicates, and c is a constant defined as:

         1 / G            for standard BRR (i.e. fay==0), or

         1 / (G*(1-k)^2)  for Fay's method.


{title:Acknowledgements}

{p}{cmd:brrtab} consists largely of the ado file code from official Stata's {cmd:svytab} command, version 1.1.6,
modified to calculate (co)variances differently.
I would like to thank Bobby Gutierrez at StataCorp for advice on implementation of BRR.


{title:Author}

	Nick Winter
	Cornell University
	nw53@cornell.edu

