Differences between revisions 1 and 2
Revision 1 as of 2023-06-09 14:48:09
Size: 1123
Comment:
Revision 2 as of 2025-10-24 17:34:08
Size: 1083
Comment: Rewrite
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The '''`recode`''' command replaces values of a variable. '''`recode-`''' recodes a variable.
Line 26: Line 26:
In the context of the `recode` command, numeric ranges are inclusive and capture non-integers. In the context of `-recode-`, numeric ranges are inclusive and capture non-integers.
Line 40: Line 40:
If creating a new variable, the missing value is set for all rows that were filtered out of the `recode` command (by either `if` or `in`). To instead copy the source variable's value for these rows, use the '''`copyrest`''' option. 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.
Line 48: Line 48:
[[https://www.stata.com/manuals/drecode.pdf|Stata manual for recode]] [[https://www.stata.com/manuals/drecode.pdf|Stata manual for -recode-]]

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:

  • nonmissing

  • missing

  • else

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)