.-
help for ^tomode^
.-

Change values of a variable to mode(s)
--------------------------------------

    ^tomode^ varname [^if^ exp] [^in^ range]
    ^,^ { ^g^enerate^(^newvar^)^ | ^replace^ }
    [ ^by(^byvarlist^)^ { ^uni^que | ^m^inmode } ^o^chmiss ^use^miss ]

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

^tomode^ generates a new variable in which values of varname are changed
to equal the mode, or replaces varname in this way.

Alternatively, ^tomode^ may be regarded as a way of storing modes,
defined for all or some of the observations of varname or by groups of
observations of varname.

varname may be numeric or string.

The mode is by default the most common non-missing value. If there are
two or more values with the same maximum frequency, the highest mode (in
sort order) is used by default.


Options
-------

^generate(^newvar^)^ specifies that values are to be placed in the new
    variable newvar.

^replace^ specifies that varname is to be overwritten with any changed
    values.

One of these two options must be specified.

^by(^byvarlist^)^ specifies that operations are to be carried out
    separately for groups defined by byvarlist.

^unique^ specifies that changes should be made only if there is a unique
    mode: that is, no ties occur.

^minmode^ specifies that if there are two or more values with the same
    maximum frequency, the lowest mode (in sort order) is used.

^unique^ and ^minmode^ are mutually exclusive.

^ochmiss^ specifies that only missing values should be changed to the
    mode. Note: To protect missing values from change, exclude them by
    e.g.
    ^tomode^ ... ^if^ varname ^< .^

^usemiss^ specifies that it is acceptable to use missing values in
    determination of the mode. That is, the mode itself may be missing.


Examples
--------

    . ^tomode rep78, gen(Rep78)^
    . ^tomode rep78, gen(Rep78) by(foreign)^
    . ^tomode rep78, replace^


Authors
-------

         Nicholas J. Cox, University of Durham, U.K.
         n.j.cox@@durham.ac.uk

         Fred Wolfe, Arthritis Research Center, Wichita, Kansas
         fwolfe@@southwind.net


Acknowledgement
---------------

        Steven Stillman suggested the original problem.


