Clean and prepare your data
How to build a data dictionary that prevents data cleaning errors
Define every variable, its allowed values, and validation rules before you collect, so cleaning does not become your analysis.
Every hour spent cleaning data after collection is usually an hour that could have been prevented before collection. A data dictionary defines every variable, its allowed values, and its validation rules before the first participant is entered. The software then rejects many errors automatically, instead of leaving them for analysis day.
The problemCleaning becomes the analysis
You open the spreadsheet to run your first test and find ages typed as words, a sex column with nine spellings, dates in three formats, and blank cells you cannot tell from real zeros. None of it was caught when it was entered, so all of it lands on you now. A data dictionary moves that work to the start, where it is cheap, and lets the data-entry tool enforce it.
What it isOne row per variable
A data dictionary (REDCap calls it the instrument; other tools call it a codebook or variable dictionary) is a table with one row for every variable you will collect. It is the specification your research database, REDCap and other clinical research databases, enforces at the point of entry. The columns that carry the work:
- Variable name. Stable, machine-readable name (for example
age_years). - Field type. Integer, text, date, radio button, checkbox, calculated field.
- Label. The question shown to the person entering data.
- Choices. Allowed coded values.
- Validation. Data type and acceptable range.
- Identifier. Whether the field contains personal identifiers.
A minimal dictionary (REDCap-style)
variable type label choices / validation identifier record_id text (auto) no age_years text Age in years integer, 18-120 no sex radio Sex at birth 1, Male | 2, Female no consent_date text Date of consent date_dmy no initials text Participant initials - yes
The age_years rule (integer, 18-120) refuses “forty” and “220” at entry. The coded sex choices refuse a tenth spelling. initials is flagged as an identifier, so you know to remove it before sharing.
ValidationRules that catch the error at entry
Set the type and range once and the tool refuses anything that fails: an integer field will not accept text, a date_dmy field will not accept 31/02/2026, a minimum and maximum fence out impossible values. Use coded choices instead of a free-text box wherever the answer is a category, and mark fields that must not be blank as required.
But validation reduces errors; it does not guarantee correctness. It cannot tell whether a value is true, only whether it is possible. A participant aged 52 can still be entered as 25, and validation will accept it. It catches impossible values, not incorrect ones. That distinction is easy to forget and worth keeping in front of you.
The same four entries, with and without a dictionary
without a dictionary with a dictionary sex Male, male, M, m, Female, F 1, Male | 2, Female age “forty” accepted as text rejected age 220 accepted rejected date 31/02/2026 accepted rejected
ThenRead it into R or Python
Because every variable already has a defined type, R and Python import the data with far fewer surprises. Most of the cleaning work has already happened during collection.
R
library(REDCapR)
d <- redcap_read(redcap_uri = uri, token = token)$data
# or from a CSV export:
d <- readr::read_csv("data.csv")
Python
import pandas as pd
d = pd.read_csv("data.csv")
Why this mattersMost analysis problems start at collection
Most analysis problems are data-collection problems discovered too late. A statistician cannot recover information that was never collected consistently. An hour spent on the data dictionary usually saves many hours of cleaning, recoding, and checking before analysis, and it protects results you could not otherwise defend.
ChecklistBefore you open recruitment
Five checks
- Every variable has a name, a type, and a label.
- Every category field uses coded choices, not free text.
- Numbers and dates have a validation type and a plausible min and max.
- Required fields are marked required.
- Every field that could identify a person is flagged as an identifier.
Related guidesRead next
Want it built for you? DictVahti builds a REDCap-ready data dictionary with variable names, validation rules, coded values, and identifier flags. You review the structure before collecting data.