Virata manual

decode

Turns a coded number back into the words it stands for.

What we have

  • a labelled number back to the words it stands for

Coming later

Nothing known to be missing.

How you write it

decode var, generate(newvar)

Square brackets mean optional. A vertical bar means choose one.

What it does

The reverse of encode. A column of 1s and 2s labelled "Male" and "Female" becomes a column actually containing the words, which is what you want when you are about to export the file to someone who does not have the labels.

Try it

Every example below was run after sysuse vira.sample02, clear.

. decode sector, generate(sector_text)
The same thing in pandas and in R

pandas

labels = {1: 'Rural', 2: 'Urban'}
df["sector_text"] = df["sector"].map(labels)

R

# no R form for `decode` yet -- see docs/r-equivalents.md

Nearby

generate replace egen recode rename order