Tutorials › Regression Analysis (Undergraduate) › Recoding Categories With a Traceable Map

Data Structure and Variable Preparation · Tutorial 46 of 991

Recoding Categories With a Traceable Map

Build an explicit, auditable map from original category labels to cleaned labels while preserving the source data and checking that every observed value has a destination.

Beginner 9 min read

What You'll Learn

  • Define a category map as an explicit rule from each observed label to one cleaned label.
  • Distinguish recoding from overwriting or silently correcting the original field.
  • Check that every observed nonmissing value has exactly one mapped destination.
  • Reconcile category counts and row totals before and after recoding.
  • Handle an unexpected label by investigating it before changing the map.
  • Document the map so another analyst can reproduce the recode.

Why a Traceable Map Matters

Category labels that seem to describe the same group may be recorded in different ways. A data field might contain “Phone,” “telephone,” and “PHONE.” If these labels are intended to represent the same response, an analyst may recode them to a common label. But a recode is only trustworthy when it is clear which original values were changed, what each became, and whether every observed value was handled.

A traceable map makes that rule visible and checkable. It also protects the original information: if a decision later needs revision, the recode can be rebuilt from the preserved source field rather than guessed from a modified one. Recoding is a preparation decision, not evidence that the categories have a particular relationship with an outcome.

Definition: A category map is an explicit rule assigning each observed, nonmissing value of an original categorical field to one cleaned value. A map may combine several original labels into one cleaned label, but each original value must have exactly one stated destination. The original field is retained unchanged, and the recoded field is stored separately.

Specify the Map Before Applying It

Start by listing the distinct values actually present in the original field, not only the values expected from a questionnaire or codebook. Then make a mapping table with one row for every observed nonmissing value. The destination should be explicit, including when the destination is the same as the original value. This makes it possible to distinguish a deliberate choice to keep a label from a value that was simply overlooked.

A map is a function: the same original value always receives the same destination. Several original values may share a destination, as with capitalization variants. But one original value cannot be assigned to two destinations by the same map. If a label is ambiguous and its destination depends on other information, investigate the records or define a separate rule using that information; do not pretend that a one-field map resolves the ambiguity.

The map should reflect the meaning of the values and the purpose of the analysis. Similar-looking labels are not automatically equivalent. For example, “Other” and “Unknown” have different meanings: one may be a valid response outside the listed options, while the other indicates that the value is not known. Combining them can remove useful information. Likewise, do not infer an ordering or numerical meaning merely because cleaned labels can be listed in a sequence.

1
Inventory the source values.
Count distinct observed labels in the original field, keeping missing values separate from nonmissing categories.
2
Write one destination per value.
Record the cleaned label for every observed nonmissing value, including labels that remain unchanged.
3
Apply the map to a new field.
Keep the original field intact so the recoding can be checked and revised.
4
Audit coverage and counts.
Confirm that there are no unmapped values and reconcile the mapped category counts with the original number of nonmissing records.

Worked Example: Combining Labels for Contact Method

Worked Example: Combining Labels for Contact Method

Suppose a hypothetical service form has eight records in an original field called contact_raw. The values are: record 1, “Phone”; record 2, “telephone”; record 3, “Web portal”; record 4, “PHONE”; record 5, “Telephone”; record 6, “portal”; record 7, “phone”; and record 8, “TELEPHONE.” The analyst has confirmed that the phone variants mean the same contact method and that “Web portal” and “portal” refer to the same method.

The map lists each distinct observed value and its destination. The original spelling remains visible in the first column.

Original valueCleaned value
PhoneTelephone
telephoneTelephone
Web portalPortal
PHONETelephone
TelephoneTelephone
portalPortal
phoneTelephone
TELEPHONETelephone

Applying this map creates a separate cleaned field, such as contact_clean. Records 1, 2, 4, 5, 7, and 8 map to “Telephone,” giving six records. Records 3 and 6 map to “Portal,” giving two records. The arithmetic check is:

$$ 6 + 2 = 8 $$

There were eight nonmissing original values and there are eight mapped values, so the counts reconcile. That check would not, by itself, prove that the chosen groupings are substantively appropriate; it verifies that no record disappeared from the recode.

Why Count Reconciliation Works

The count check follows from how a complete, single-destination map assigns records. Each nonmissing record contributes to exactly one cleaned category. If the cleaned categories are mutually exclusive and together include every mapped record, adding their counts must give the number of mapped nonmissing records.

$$ \sum_{j=1}^{k} n_j = n_{\text{mapped}} $$

Here, \(n_j\) is the number of records assigned to cleaned category \(j\), \(k\) is the number of cleaned categories, and \(n_{\text{mapped}}\) is the number of nonmissing records to which the map was applied. In the contact-method example, \(k=2\), the two counts are six and two, and \(n_{\text{mapped}}=8\). If the sum were seven, one record might have been dropped or left unmapped. If the sum were nine, a record might have been counted more than once or the categories might overlap.

Missing values need a separate check. Unless the analysis plan explicitly defines a missing-value category, missingness is not an observed response label to be recoded as though it were one. Keep missing values missing in the cleaned field and report how many records were missing, so the count reconciliation is clear about which records it covers.

Worked Example: Combining Labels Without Losing a Distinction

Worked Example: Combining Education Labels

A hypothetical survey records the highest education response for ten respondents as follows: “H.S.,” “High school,” “high-school,” “College,” “University,” “College,” “HS,” “university,” “High school,” and “Graduate.” For this particular summary, the analyst wants one broad “High school” group, one “Postsecondary” group for college or university, and a separate “Graduate” group. The choice to combine college and university is an analysis decision and should be documented; it is not a claim that all education systems use those terms identically.

The map is:

Original valueCleaned value
H.S.High school
High schoolHigh school
high-schoolHigh school
CollegePostsecondary
UniversityPostsecondary
HSHigh school
universityPostsecondary
GraduateGraduate

Five records map to “High school”: records 1, 2, 3, 7, and 9. Four map to “Postsecondary”: records 4, 5, 6, and 8. One maps to “Graduate”: record 10. The cleaned counts are therefore five, four, and one, and their total is \(5+4+1=10\), matching the ten nonmissing responses. All observed labels have an explicit destination, and “Graduate” has not been folded into the broader group without a stated reason.

Worked Example: Investigating an Unmapped Value

Worked Example: Resolving an Unmapped Status Label

A hypothetical seven-record field contains “Active,” “active,” “ACTV,” “Inactive,” “inactive,” “Actve,” and a blank value. The analyst initially has evidence that “Active,” “active,” and the approved abbreviation “ACTV” mean Active, and that both forms of “Inactive” mean Inactive. The value “Actve” is not in the initial map. It looks like a possible typing error, but appearance alone is not enough to assign it a destination.

The first audit finds five mapped nonmissing records, one unmapped nonmissing record (“Actve”), and one missing value. The map is not yet complete for the observed nonmissing values, so the analyst should not report a final recode as though all six had been handled. The analyst checks the source record and the data-entry documentation. In this hypothetical case, that review confirms that “Actve” is a typing error for “Active.”

The analyst records that decision and adds an explicit row mapping “Actve” to “Active.” The final counts are four Active records (“Active,” “active,” “ACTV,” and “Actve”), two Inactive records, and one missing value. Thus, six nonmissing records are mapped, and \(4+2=6\). The seventh record remains missing rather than being assigned to either status. If the source check had not resolved “Actve,” the responsible result would be to flag it for review, not guess.

Keep the Recode Reproducible

A useful record of a recode includes the original field name, the cleaned field name, the full mapping table, the reason for any many-to-one grouping, and the date or version of the decision. When a label is corrected based on a source record, note the evidence for that correction. These details allow another analyst to reproduce the cleaned field and help distinguish a justified correction from an undocumented assumption.

After applying the map, compare the original and cleaned values. A frequency table of the original labels helps confirm that the map covers what actually occurred; a frequency table of the cleaned labels shows the resulting group sizes. Check that the number of mapped records equals the original number of nonmissing records, and separately confirm the missing count. These are basic audits, not guarantees that every category decision is correct, so the mapping choices still need a substantive review.

Common Mistakes

  • Overwriting the original field. This removes the direct evidence needed to check or revise the recode. Keep a separate cleaned field.
  • Mapping only the values expected in advance. An unexpected spelling or category may occur in the data. Inventory observed values and verify complete coverage.
  • Assuming similar labels must mean the same thing. Combine labels only when their meanings and the purpose of the analysis support it.
  • Silently assigning an unfamiliar value. An apparent typo may be a different category. Investigate it and document the decision before adding a destination.
  • Counting missing values as ordinary responses. Keep missingness distinct unless there is a clearly defined reason to create a missing category.
  • Checking only the cleaned labels. A plausible-looking final table can conceal an incorrect mapping. Retain the original-to-cleaned table and compare the record counts.
Key takeaway: A reliable category recode is explicit, complete for the observed values, and reproducible. Preserve the original field, assign each observed nonmissing label one documented destination, investigate unexpected values, and reconcile the resulting counts.

Check Your Understanding

Answer each question using the principles of a traceable map.

  1. A field contains “Email,” “email,” and “E-mail.” What should you inspect and document before mapping them to one cleaned label?
  2. Why should the original category field be retained after a cleaned field is created?
  3. A recode has 24 nonmissing input records, but the cleaned category counts sum to 23. Give two possible explanations to investigate.
  4. A label appears to be a typo, but the source record cannot be checked. What is a defensible next step, and why is silent correction risky?
  5. A field has 18 nonmissing records and 2 missing records. If every nonmissing record is mapped exactly once, what should the cleaned category counts sum to, and how should the missing records be handled?