Datasets and Codebooks
The text below is a transcript of the video above, edited with AI assistance for clarity and flow. Where the two differ, the video is the authoritative version.
You’ll learn to
Every good dataset comes with a codebook: an accompanying document that teaches you what is what in the dataset. In this video, you will learn to:
- Identify how datasets are structured.
- Use a codebook to interpret variable meanings, coding schemes, and missing-value conventions.
Example 1: Global Competition and Brexit

American Political Science Review (2018)
We start with a replication dataset. It is a regional-level dataset covering regions of the UK, and one of its variables is the share of voters in each region who voted Leave in the Brexit referendum. It comes from a highly influential paper in political science, published in the American Political Science Review in 2018.
| region_name | leave_share | unemployment |
|---|---|---|
| Hartlepool and Stockton-on-Tees | 64.19 | 8.1 |
| South Teesside | 65.86 | 9.7 |
| Darlington | 56.18 | 6.7 |
| Durham CC | 57.55 | 6.9 |
| Northumberland | 54.11 | 5.1 |
| Tyneside | 54.60 | 8 |
| Sunderland | 61.34 | 7.9 |
| West Cumbria | 60.19 | 6.5 |
| East Cumbria | 53.34 | 3.3 |
| Manchester | 39.64 | 8.2 |
When we get the replication dataset from the authors, it looks more or less like this. I have changed it a little to make it more pedagogical, adding the names of the regions on the left-hand side.
You can see that the rows hold observations. Each row is a region of the UK: Northumberland, West Cumbria and Manchester, for example. The columns contain variables. These regions vary in a lot of characteristics, and two of those characteristics are shown here: the Leave share and the unemployment rate. The regions of Manchester, West Cumbria and East Cumbria had different percentages of voters who voted Leave in the Brexit referendum, and they had different unemployment rates in 2016. Those are two variables.
This is just a snapshot of the data. The original dataset has more than 100 regions and many other variables besides the Leave share and the unemployment rate.
Codebooks
The Brexit data comes with a codebook. So what is a codebook? Every good dataset has one. It is a document that provides researchers with necessary information about the dataset, for example:
- Full explanations of what information each variable carries.
- Sources, measurement choices, timespans.
- Coding schemes.
Codebook example: Global Competition and Brexit
In this example, the variable names shown so far are pretty straightforward: the Leave share is the share of Leave votes, unemployment is the unemployment rate, and the region name is the name of the region. But it will not always be like that, as the second example shows very clearly.
Even within the Global Competition and Brexit data, if you look at additional variables you will find names such as eu_15_imm_growth. When you open that dataset in Stata and see a column with that title, the codebook is what explains it:
- eu_15_imm_growth: growth of immigrants from EU15 countries over 2001-2011. Source: UK Census.
- share_council_rent: share of the population in public housing in 2001. Source: UK Census.
The Leave share and unemployment are straightforward, but variables named like these are not going to be as clear. Variable names can be cryptic, and the codebook is the document that tells you exactly what is what in the dataset.
Example 2: British Election Study

Let us move to a different example: the British Election Study, one of the most important and longest-running electoral surveys in the world.
| finalserialno | b01 | b02 | b04 | b05 |
|---|---|---|---|---|
| 101103 | Yes, voted | Liberal Democrats | . | In person |
| 101112 | Yes, voted | Reform UK | . | In person |
| 101201 | Yes, voted | Conservatives | . | In person |
| 101202 | Yes, voted | Refused | . | In person |
| 101203 | Yes, voted | Conservatives | . | In person |
| 101208 | Yes, voted | Labour | . | By post |
| 101212 | Yes, voted | Don’t know | . | By post |
| 101213 | No, did not vote | . | Other (WRITE IN) | . |
| 102104 | Yes, voted | Labour | . | By post |
| 102105 | Yes, voted | Reform UK | . | By post |
This is also a snapshot, with only 10 observations (10 rows) and just a few variables. The numbers in the first column are identifiers: each number represents a person. The name of the person cannot be revealed, because this is supposed to be confidential, so you get numbers identifying people instead.
Now look at the columns: b01, b02, b04, b05. You have no idea what each of these columns is. To find out, you need to go to the codebook.
Codebook example: British Election Study
b02: Which party did you vote for in the last General Election?
| Value | Label |
|---|---|
| -999 | Not stated |
| -2 | Refused |
| -1 | Don’t know |
| 1 | Labour |
| 2 | Conservatives |
| 3 | Liberal Democrats |
| 4 | Scottish National Party (SNP) |
| 5 | Plaid Cymru |
| 6 | Green Party |
| 8 | Reform UK |
| 9 | Other (WRITE IN) |
| 10 | An independent candidate |
The codebook for the British Election Study is a PDF. When you open it, you see that b02 is the question “Which party did you vote for in the last General Election?” Below the question, you have the way in which it is coded.
Go back to b02 in the data. This is what it looks like in Stata, and you can see labels there: one person voted Liberal Democrat, person number two voted Reform UK, number three Conservative, and number four refused to answer. Those blue values are labels that Stata shows you. Behind the curtain, however, they are actually numbers: −2 is Refused, 1 is Labour, 2 is Conservatives, 3 is Liberal Democrats, and so on.
This means that if you tried to carry out mathematical operations with this variable, the computer would probably do it for you, but the result would not mean anything. If you took the mean, for example, you would get a number that is absolutely meaningless, because this is the party that someone voted for in the last general election. It is a nominal variable, not a variable you can take means of. It is not the case that Reform UK is twice as much as the Scottish National Party, even though Reform UK is coded 8 and the Scottish National Party is coded 4.
It is important to keep that in mind: you need to know not only the type of the variable but also how it is coded, because a nominal variable might be coded as numbers in a dataset. Making the mistake of trying to get the mean of a variable like this is more common than you think. Knowing the types of variables and knowing the coding is going to be very important as you start to open and navigate datasets and read their codebooks.
Recap
- A dataset is a table where rows are observations and columns are variables.
- A codebook documents what variables mean and how values are coded.
- Working with data inevitably involves switching between Stata, or whatever software you use, and documentation, meaning the codebook. You will be going back and forth between different windows on your computer, one showing Stata and one showing the codebook.
Why this matters
Real-world datasets rarely “explain themselves”. You are going to get cryptic variable names that you will have to look up in the codebook to find out what they are. Learning to read this documentation is a core data-analysis skill.