help dummify https://github.com/gaksaray/stata-gautils/

Title

dummify -- Create indicator variables with automatic variable labels

Syntax

dummify varname [, options]

Main
stub(name) prefix for the new indicator variables; default is varname

label(string) stem used in the variable labels; default is the variable label of varname

Base category
base omit the lowest level, creating no indicator for it

base(#) omit the level whose value is #

Display
force proceed even when varname has more than 100 distinct levels

all show every row of the summary table

Positioning
order_options first, last, before(varname), after(varname); see order

Description

dummify creates a set of indicator (0/1) variables from a categorical
variable, one for each level, and labels each one automatically in the form
"variable label = value label". It also reports a compact summary table
listing each level, its value label, and the indicator created for it.
Essentially, it is a more convenient implementation of
tabulate, generate(), producing indicators that
carry meaningful variable labels rather than the bare stems that
tabulate, generate() leaves behind.

varname must be numeric and contain only non-negative integer values. By
default an indicator is created for every level; base or base(#)
designates one level as an omitted reference category. An indicator equals 1
where varname takes the corresponding value and 0 elsewhere, and is left
missing wherever varname is missing.

Options

stub(name) specifies the prefix for the new indicator
variables. The default is varname. Each indicator is named
stub#, such as region1 or region2.

When stub ends in a digit, an underscore is inserted between the stub
and the level so the value stays legible: region1 yields region1_1
rather than the ambiguous region11.

label(string) specifies the stem used to build the variable
labels, which take the form "string = value label". The default is the
variable label of varname, or its name if it has no variable label.

base designates the lowest level of varname as the omitted base
category. No indicator is created for it.

base(#) designates the level whose value is # as the
omitted base category, in the same way that ib#. sets the base
level for factor variables. It is an error to specify a value that does not
occur in varname. base and base() may not be combined.

force allows dummify to proceed when varname has more than 100
distinct levels. Before creating any variables, dummify checks that the
whole operation can complete, so it never leaves a half-built set behind. It
stops when varname has more than 100 distinct levels (a safeguard against
accidental use on a near-continuous variable, which force overrides), or
when too few free variable slots remain; see memory.

all shows every row of the summary table. By default, when varname has
more than 21 levels, only the first and last 10 are shown (plus the base
category, if any), with the omitted rows collapsed into a single divider.

order_options are first, last, before(varname), and
after(varname), which position the new indicators in the dataset; see
order. By default the indicators are placed immediately after
varname.

Examples

Setup

. sysuse lifeexp, clear

One indicator per region, placed first in the dataset

. dummify region, first

Custom stub and label, with value 2 as the omitted base category

. dummify region, stub(cont) label(Continent) base(2)

A variable with no value labels; the label stem is paired with each value

. dummify lexp, label(Life expectancy)

Stored results

dummify stores the following in r():

Scalars

r(k) number of indicator variables created

Macros

r(varname) name of the source variable

r(indicators) names of the indicator variables created

r(base) base category value, if any

Author

Gorkem Aksaray, Trinity College Dublin.

Email: aksarayg@tcd.ie

Personal Website: sites.google.com/site/gorkemak

GitHub: github.com/gaksaray