DDI-Codebook 2.5 XML: what it is and how to export your variables
DDI-Codebook is an international XML standard for documenting a research dataset: the study, its data files and every variable, with labels, question text and value labels. It comes from the Data Documentation Initiative (DDI) and is widely used by social science data archives and data catalogues. This guide explains what a DDI-Codebook file contains, when you need one, and how to produce it without writing XML by hand.
What is DDI-Codebook?
The Data Documentation Initiative (DDI) is a metadata standard maintained by the DDI Alliance. It has two main branches. DDI-Codebook (current version 2.5) describes a single study in one XML document — essentially a codebook in a structured, machine-readable form. DDI-Lifecycle (version 3) describes metadata across the whole research lifecycle and is more complex. For documenting one dataset, DDI-Codebook is the common choice.
Because the format is standardised, a DDI codebook can be read by archive systems, turned into a searchable catalogue entry or a printable codebook, and checked automatically against the official XML schema.
What a DDI-Codebook XML file contains
- Study description (
stdyDscr): the title of the study, an abstract and the authors. - File description (
fileDscr): one entry per data file or table. - Variable description (
dataDscr→var): for every variable its name, label (labl), question text (qstn), value labels as categories (catgry), format and notes. - Universe: who a question applied to — for example a question only asked of smokers.
- Languages: labels and question text can be included in more than one language, marked with
xml:lang.
In other words, it holds the same information as a good codebook — see how to structure a codebook — in a form that software can read.
When do you need a DDI codebook?
- Depositing data in an archive. Many social science archives describe their collections in DDI. Supplying structured metadata makes the deposit easier to process and the data easier to find. Requirements differ per archive, so check the deposit guidelines first.
- A data catalogue or data portal. If your institution or consortium runs a catalogue, DDI is a common exchange format for variable-level metadata.
- FAIR data plans. Funders increasingly ask for data to be findable and reusable. Rich, standardised metadata is one of the practical ways to show that in a data management plan.
- Reuse within a long-running study. A machine-readable codebook makes it easier to compare variables between waves and to generate documentation instead of retyping it.
How to create a DDI-Codebook XML file
There are three common routes:
- By hand or with a script. Possible for a small dataset if you know XML, but slow and easy to get wrong. Always validate the result against the official schema.
- With a dedicated DDI editor. Specialised tools exist, some of them commercial. They are powerful but are often aimed at archives rather than individual research teams.
- Export it from the data dictionary you already keep. If your variables are documented in one place, the DDI file can be generated from there whenever you need it.
Exporting DDI-Codebook 2.5 from VarBook
In VarBook, a research data dictionary, DDI export is built into the Viewer:
- Search or browse the dictionary and tick the variables you want to include.
- Open Variable selection and choose Export ▾ → DDI-Codebook XML.
- The browser creates the XML file. Nothing is sent to a server.
The file contains the study description (title, description and authors of the data file), one file description per table, and for every selected variable its label, question text, value labels, format and notes. Descriptions are included in both languages when the dictionary is bilingual, and skip logic is written as the universe ("Asked if …"). The output was checked against the official DDI-Codebook 2.5 XML schema of the DDI Alliance. The same menu also offers a Frictionless Data Package, Stata .do, CSV and a printable codebook.
No VarBook? The free codebook generator turns an Excel or CSV variable list into a printable codebook, which is often the first step.
Checklist before you share a DDI codebook
- Does the file validate against the DDI-Codebook 2.5 schema (for example with
xmllint --schema codebook.xsd)? - Does every variable have a label, and do coded variables have all their value labels?
- Are missing-value codes (for example -99, -98) labelled, so they are not read as real values?
- Is the study title and abstract understandable for someone outside your team?
- If you include two languages, are both complete?
DDI codebook: frequently asked questions
What is the difference between DDI-Codebook and DDI-Lifecycle?
DDI-Codebook (version 2.5) describes one study and its data files in a single XML document, much like a traditional codebook. DDI-Lifecycle (version 3) can describe metadata across the whole research lifecycle and reuse it between studies, for example a question used in several waves. It is more powerful but also more complex. For documenting one dataset, DDI-Codebook is usually enough.
Does my data archive require DDI?
Requirements differ per archive and per discipline. Many archives accept a codebook as PDF or spreadsheet alongside the data; others ask for, or produce, DDI metadata themselves. Check the deposit guidelines of your archive before you start. A DDI file is never a disadvantage: it is structured, machine-readable and can always be turned into a readable document.
Is DDI the same as a Frictionless Data Package?
No. Both describe data in a machine-readable way, but DDI comes from the social science archive world and focuses on study, question and variable documentation, while a Frictionless Data Package (JSON) focuses on describing data files and their columns so tools can load and validate them. VarBook can export both.