Writing · Research Data

How to write a codebook (data dictionary) for your research data

← All writing

Every dataset has a codebook, whether or not anyone wrote it down. It's the knowledge that q7_r is the reverse-coded version of question 7, that 99 means "refused," that income is in thousands, and that the 2023 wave dropped two answer options. If that knowledge lives only in your head, the dataset stops being usable the day you move on, and a surprising number of times, "the day you move on" turns out to be next semester.

This guide covers what a codebook is, what goes in one, a template you can copy, and how to build one without starting from a blank page.

Codebook, data dictionary: what's the difference?

In practice, not much. Codebook is the older term from survey research, and it often includes the full question wording and response frequencies. Data dictionary is more common in databases, health research, and administrative data, and it's usually a table: one row per variable, one column per attribute. Funders and repositories use both words and mean the same thing: a document that tells a stranger what every variable in your data means.

Pick whichever term your field uses. The rest of this guide says "codebook" for short.

Why it's worth the hour

What goes in a codebook

A good codebook has two parts: a short description of the dataset as a whole, and a variable-by-variable listing.

About the dataset

For each variable

That "source" column is the one people leave out, and it's often the most useful. "Satisfaction" means very little until you know whether respondents were asked about their course, their advisor, or the whole institution.

A template you can copy

For most projects a spreadsheet is enough. Here's the layout, with two sample rows:

VariableLabelTypeValues / unitsMissing codesSourceNotes
age_enrAge at enrollmentNumericYears, 16 to 80-9 = not recordedRegistrar record, birth date subtracted from term start dateTop-coded at 80 for privacy
sat_advSatisfaction with academic advisingCategorical1 = Very dissatisfied ... 5 = Very satisfied8 = Don't know; 9 = Refused; -1 = Not asked (no advisor)Survey Q12: "How satisfied are you with the academic advising you've received this year?"Wording changed in the 2025 wave; see note 3

Save it as CSV next to the data (and as a PDF too, if people will print it). Put the dataset-level description at the top of your README, or in a short first tab, and point to it from the codebook. The guide to writing a dataset README covers what it should say, and the guide to organizing research data shows where it lives.

Don't start from a blank page

Statistical software already knows most of what goes in a codebook, as long as you've set variable and value labels. Generate a draft, then add what the software can't know: sources, reasons for missingness, and notes.

If your data came from a spreadsheet with no labels at all, write the codebook first and apply labels from it. It's faster than it sounds, and your cleaning code gets shorter.

Mistakes that make a codebook useless

When you deposit the data

Upload the codebook as a separate file alongside the data, not buried in a zip. Mention it in the repository description, and name it in your data availability statement if part of the data is restricted: the codebook can almost always be public even when the data can't, and it lets people judge whether it's worth applying for access. Some social science archives, ICPSR among them, will prepare a formal codebook in the DDI metadata standard when you deposit, but they'll still ask for your documentation to start from. The repository guide covers where to deposit.

If you support researchers

Codebooks are a good hands-on workshop: people bring their own data, generate a draft in their software, and leave with something finished. It pairs well with a DMP or data organization session. If your campus is building that kind of support, the guide to starting research data services is a place to begin, and I help institutions set it up. Get in touch if that would help.

Common questions

Is a codebook the same as a data dictionary? For most purposes, yes. Codebook is the traditional survey research term and often includes question wording and frequencies; data dictionary is more common for databases and administrative data. Both describe every variable so someone else can use the data correctly.

What format should a codebook be in? An open format such as CSV or a spreadsheet saved as CSV, plus a PDF if people will read it on paper. Avoid formats that only open in one statistics package.

Do I need a codebook for qualitative data? You need documentation, though it looks different: a list of files, participant attributes and how they're coded, the interview guide, and your coding scheme with definitions. The coding scheme is often called a codebook in qualitative work too.

Can software make the codebook for me? It can make a good draft. Stata, SPSS, R, REDCap, and Qualtrics can all export names, labels, and codes. You still need to add sources, missing-value reasons, and notes on how variables were derived.


Samah Alshrief, Ph.D.

AI data scientist and research-computing specialist. I help researchers and universities with research data management, data services, and private AI. Get in touch →