VarBook · Guides

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:

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:

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.

ColumnRequired?What goes in it
VariableYesThe exact name used in the data file, e.g. smoke_status.
DescriptionYesWhat the variable measures, in a full sentence. Include the question text for survey items.
TypeRecommendedInteger, decimal, text, date, categorical. Add the unit (kg, mmHg) or format (YYYY-MM-DD).
ValuesFor coded variablesEvery code and its meaning, e.g. 0=Never; 1=Former; 2=Current.
Missing codesOptionalCodes that mean missing, and why, e.g. -99=Not answered; -98=Not applicable.
Source / derivationOptionalQuestionnaire 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:

VariableDescriptionTypeValues
participant_idUnique participant identifier assigned at enrolmentInteger
sexSex assigned at birth, as reported by the participantCategorical1=Male; 2=Female; 3=Other
smoke_statusQ12: "Do you smoke, or have you smoked in the past?"Categorical0=Never; 1=Former; 2=Current; -99=Not answered
weight_kgBody weight measured at baseline visit, in kilogramsDecimal (1 dp)
visit_dateDate of baseline visit (YYYY-MM-DD)Date

A few habits keep value labels trustworthy:

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:

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):

  1. Copy the range from Excel (header row included) and paste it into the box, or upload the .xlsx file directly (CSV works too).
  2. 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.
  3. Generate the codebook. Value labels written as code=label; code=label (or code:label) are turned into a small table per variable; anything else is shown as plain text.
  4. 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:

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