Stata Recode

recode- recodes a variable.


Usage

recode foo (0=.)
recode foo (0=.), generate(bar)
recode foo (0=.) if foo!=., generate(bar)
recode foo (0=.) in 1/10, generate(bar)

Numeric lists are valid on the left side of an instruction.

recode foo (0 9=.)

In the context of -recode-, numeric ranges are inclusive and capture non-integers.

recode foo (1/2=0) (3/5=1), generate(baz)

The min and max keywords dynamically capture the lowest and highest non-missing values.

The following keywords can be used to capture values that fall through preceding rules:

If creating a new variable, the missing value is set for all rows that were filtered out of -recode- (by either if or in). To instead copy the source variable's value for these rows, use the copyrest option.


See also

Stata manual for -recode-


CategoryRicottone

Stata/Recode (last edited 2025-10-24 17:34:08 by DominicRicottone)