How to create a codebook (data dictionary) from an Excel variable list
A codebook is a document that describes every variable in a dataset: its name, the question or description, its value labels and the codes used for missing values. Most research teams already have the raw material for a codebook: a spreadsheet with variable names and a short description of each one. The gap is usually not information but structure. This guide walks through turning that spreadsheet into a codebook someone outside your team can actually use — which columns you need, how to write value labels and missing-value codes, and what to check before you share it.
This guide is about codebooks for quantitative data: survey responses, case report forms, cohort and registry data. If you are looking for a codebook for qualitative coding of interviews (themes, code definitions, example quotes), that is a different document with the same name.
What is a codebook, and what should it contain?
A codebook describes every variable in a dataset so that a person who was not involved in collecting the data can interpret it correctly. For each variable, a reader should be able to answer five questions without asking you:
- What is it called? The exact variable name as it appears in the data file.
- What does it measure? A plain-language description, ideally including the question text or the source of the value.
- What kind of value is it? Integer, decimal, text, date, categorical — and the unit or format where relevant.
- What do the codes mean? For categorical variables, the meaning of every code (1 = Yes, 2 = No).
- What does "missing" look like? Whether empty cells, -99 or 999 mean "not asked", "refused" or "not applicable".
If your spreadsheet answers those five questions for every row, you have a codebook. Everything else is formatting.
Step 1: Get to one row per variable
Variable lists grow organically, so the first job is to make the structure regular. The rule is simple: one row per variable, one column per attribute. In practice that means:
- Remove merged cells, section-header rows, blank spacer rows and colour-coding that carries meaning. If a colour means "derived variable", turn it into a column.
- Make the first row your column headers, and nothing else.
- Check that every variable name is unique. Duplicates are common when a list was assembled from several questionnaires or waves.
- Make sure the names in the list exactly match the column names in the data file — same spelling, same case, same suffixes.
If your data comes from SPSS, the Variable View already has this shape; if it comes from REDCap or Castor EDC, the exported data dictionary is a good starting point that you can tidy rather than retype.
Step 2: Use a small, predictable set of columns
You do not need dozens of columns. Four cover most studies, and a few optional ones make the codebook much more useful.
| Column | Required? | What goes in it |
|---|---|---|
| Variable | Yes | The exact name used in the data file, e.g. smoke_status. |
| Description | Yes | What the variable measures, in a full sentence. Include the question text for survey items. |
| Type | Recommended | Integer, decimal, text, date, categorical. Add the unit (kg, mmHg) or format (YYYY-MM-DD). |
| Values | For coded variables | Every code and its meaning, e.g. 0=Never; 1=Former; 2=Current. |
| Missing codes | Optional | Codes that mean missing, and why, e.g. -99=Not answered; -98=Not applicable. |
| Source / derivation | Optional | Questionnaire and item number, or the formula for a derived variable such as BMI. |
Short, conventional header names help both people and tools. A header called "Description" or "Values" is unambiguous; a header called "Info (see tab 3)" is not.
Step 3: Write value labels in one consistent format
Value labels are where codebooks most often go wrong. The same list may contain "1 = yes / 2 = no", "Y/N", "yes(1), no(0)" and a note saying "see questionnaire". Pick one format and use it everywhere. A format that is easy to read and easy for software to parse is code=label, separated by semicolons:
| Variable | Description | Type | Values |
|---|---|---|---|
| participant_id | Unique participant identifier assigned at enrolment | Integer | |
| sex | Sex assigned at birth, as reported by the participant | Categorical | 1=Male; 2=Female; 3=Other |
| smoke_status | Q12: "Do you smoke, or have you smoked in the past?" | Categorical | 0=Never; 1=Former; 2=Current; -99=Not answered |
| weight_kg | Body weight measured at baseline visit, in kilograms | Decimal (1 dp) | |
| visit_date | Date of baseline visit (YYYY-MM-DD) | Date |
A few habits keep value labels trustworthy:
- List every code, including ones nobody chose. A code missing from the codebook looks like an error in the data.
- Keep the same coding for the same concept across variables. If 1=Yes in one question and 1=No in another, someone will eventually analyse it the wrong way round.
- For scales, label both ends at minimum (
1=Strongly disagree; 5=Strongly agree), and preferably every point. - Separate pairs with semicolons rather than commas, so that labels which contain a comma ("Yes, daily") stay intact.
Step 4: Make missing values explicit
An empty cell can mean "the participant skipped this question", "this question was not shown because of routing", or "the value has not been entered yet". Those are different situations for analysis. If your study uses numeric missing codes such as -99 or -98, document what each one means and make sure the code can never be a real value for that variable — -99 is a poor missing code for a temperature change, for example.
If your study simply leaves missing values blank, say so once at the top of the codebook. Silence on this point is the most common reason people email the data manager.
Step 5: Write descriptions for someone outside the team
Descriptions written during data collection tend to be shorthand: "wt bl", "smoking Q", "see CRF p.4". Read each description as if you were a new PhD student or an external reviewer who has never seen the questionnaire. Good descriptions:
- say what was measured and when (baseline, follow-up wave, visit 3);
- include the unit, or the original question text for survey items;
- state how derived variables were calculated, including the source variables;
- flag variables that are sensitive, restricted, or no longer collected.
If your study works in two languages, decide now whether the codebook will carry both. Adding an English description column next to the original-language description is far easier than maintaining two separate files that drift apart.
Step 6: Generate a readable codebook (free, in your browser)
A tidy spreadsheet is already usable, but a formatted codebook — one block per variable with its values laid out as a small table — is much easier to read, print, attach to a data-sharing request or include as a supplement.
You can build that layout by hand in Word, write a script (R packages such as codebook or memisc, or SPSS's built-in Codebook procedure under Analyze → Reports, if your data is already labelled there), or use a generator. Our free codebook generator does this directly from a variable list (if your questionnaire is in LimeSurvey, the LimeSurvey codebook generator reads the .lss file instead):
- Copy the range from Excel (header row included) and paste it into the box, or upload the .xlsx file directly (CSV works too).
- Check the column mapping. The tool guesses which columns are the variable name, description, type and values from common header names — including Dutch ones such as omschrijving and waarden — but you confirm it.
- Generate the codebook. Value labels written as
code=label; code=label(orcode:label) are turned into a small table per variable; anything else is shown as plain text. - Print it or save it as PDF from your browser.
Everything runs in your browser; the variable list is not uploaded anywhere and no account is needed, which matters if your variable descriptions themselves are confidential.
Step 7: Check it before you share it
Before the codebook leaves your team, run through a short check:
- Coverage: does every column in the data file have a row in the codebook, and vice versa?
- Codes: for each categorical variable, does every value that actually occurs in the data appear in the value labels?
- Missing values: are all missing codes documented, and are blanks explained?
- Version: does the codebook carry a date or version number, and does it match the data release it describes?
- Outsider test: could a colleague from another project answer a basic question about the data using only the codebook?
When a spreadsheet stops being enough: data dictionary software
A codebook generated from a spreadsheet is a snapshot. That is fine for a single dataset or a data-sharing request. It becomes a problem in long-running studies and cohorts, where variables are added each wave, some are renamed or retired, and several people edit the list. The usual symptoms are familiar: multiple versions of the spreadsheet in circulation, a codebook that lags behind the database, and nobody quite sure which file is current.
At that point it is worth keeping the dictionary in one maintained place rather than regenerating documents. That is the problem VarBook was built for: a self-hosted data dictionary organised as physical file, table and field, with bilingual descriptions, reusable value ranges and sensitivity flags, where an edit is visible to every researcher as soon as it is saved. If you are not there yet, a clean spreadsheet and a generated codebook are a perfectly good place to start — and the clean spreadsheet can be imported later.
Codebook: frequently asked questions
Is a codebook the same as a data dictionary?
The terms overlap and are often used interchangeably. "Data dictionary" tends to emphasise the technical structure of the variables (names, types, formats), while "codebook" is the more common term in social and health research and usually includes value labels, question text and study context. For a single dataset, the document described in this guide serves both purposes.
Do I need special software to make a codebook?
No. A well-structured spreadsheet with the columns above is already a codebook. Software helps with formatting, consistency checks and keeping it up to date over time.
Should I include summary statistics?
It can be helpful — frequencies for categorical variables, ranges for continuous ones — especially for a public data release. It requires the data itself, not just the variable list, so it is usually produced with statistics software. A codebook without statistics is still complete as documentation.
Turn your variable list into a codebook — free, in your browser