Tabulate allele frequencies within genotypes and generate indicators
--------------------------------------------------------------------

^gtab^ ^varlist^ [if], [^g^en^(^string^)^ ^ref(^string^)^ ^rec^ode]

The command requires two arguments - the variables containing the two alleles
at the locus considered. ^iweights^ are allowed

Description
-----------

This program tabulates the number of times each allele occurs (0, 1, or 2)
within genotypes, together with its total frequency. It also computes a 
Z-test for Hardy-Weinberg equilibrium for each allele in turn, and an overall
Z-test based on a kappa statistic. Positive Z values indicate excess of 
homozygots, while negative values indicate fewer homozygots than would be 
expected under HWE. Significance should be assessed by comparing the 
Z values with the standard normal distribution.

Optionally the program computes an indicator variable for each allele which 
counts the number of times that allele occurred in this subject. Thus, these 
indicators take on the values 0, 1 or 2. The program then returns a macro, 
r(^ivars^), which contains a list of the indicator variables. This option is
useful in subsequent analysis by using logistic regression. Optionally, 
one allele may be defined as the "reference" allele, in which case no indicator
variable is created for this allele, thus ensuring that odds ratios calculated
in subsequent logistic regressions will be expressed relative to this allele.

Note that alleles coded as zero are NOT treated as missing. If you want zero 
to be treated as missing, use ^mvdecode^ (or read your input file with ^inprep^,
which deals with this automatically).


Options
-------

^gen^	  prefix string for the names of the indicator variables

^ref^	  the reference allele. If this option is set to ^_most^, the most 
	  frequent allele is used. If the option is set to "_xxx", say, the 
          allele with value label "xxx" will be taken as reference. 
          Alternatively the option can specify the numerical code for the 
          allele

^recode^  Recode alleles to consecutive integers


Returned values
---------------

^gtab^ is an ^rclass^ command and returns the following values:

r(kappa)    (scalar) Kappa statistic for Hardy-Weinberg equilibrium
r(z)        (scalar) Corresponding z-value (standard normal deviate)
r(p_val)    (scalar) p-value
r(ivars)    (macro)  When ^gen^ option is in force, a list of the generated
            indicator variables

Examples
--------

. gtab a1 a2, gen(all) ref(_most)
. gtab a1 a2, gen(all) ref(1)
. gtab a1 a2, gen(all) ref(_C)

See Also
--------

^mvdecode^, ^inprep^

Author
------

David Clayton

Diabetes and Inflammation Laboratory		Tel: 44 (0)1223 762669 
Cambridge Institute for Medical Research	Fax: 44 (0)1223 762102
Wellcome Trust/MRC Building			david.clayton@cimr.cam.ac.uk
Addenbrooke's Hospital, Cambridge, CB2 2XY	www-gene.cimr.cam.ac.uk/clayton


