Why Binary Coding Needs Explicit Labels
A yes/no question looks simple, but its numeric representation can create ambiguity. If a spreadsheet contains only 0s and 1s, a reader cannot know whether 1 means Yes or No unless the coding is documented. Nor can a blank or an “Unknown” answer safely be assigned to either value. A small, explicit coding scheme makes the data easier to check and prevents a response status from being mistaken for a substantive answer.
This is a data-preparation task: identify the two meaningful response categories, decide and record their numeric labels, and make sure every other response remains distinguishable. The numbers are codes for categories, not measurements of how much of something a person has.
Write the Meaning Before the Numbers
Before recoding responses, confirm what the question asked and which answers count as its two substantive outcomes. The categories must be mutually exclusive: one response should not qualify as both. They must also cover the substantive answers the question allows. A question such as “Was a reminder sent?” can have Yes and No as its two substantive categories. “Yes,” “No,” “Not sure,” and “Not asked” are not four equally meaningful answers to that binary question: the last two describe uncertainty or data collection status rather than a definite Yes or No.
A useful codebook entry names the variable, identifies the source question, spells out the category labels, and defines every numeric value. For example: reminder_sent; source question, “Was a reminder sent?”; 0 = No; 1 = Yes; unanswered or unknown = missing for this variable. The original response should be retained where possible, so that the recoding can be checked later.
Choosing 1 for Yes and 0 for No is common, but it is a convention, not a universal rule. Reversing the values can also be valid if the choice is documented and applied consistently. The essential requirement is not which category gets 1; it is that no one has to guess what either value means.
Use the wording of the question and its response options. Do not treat “unknown” or “not asked” as Yes or No.
State the variable name and the exact meaning of every numeric value before recoding.
Map each valid response to its documented value. Preserve or flag responses that do not match either category.
Compare counts in the source responses with counts in the encoded variable, and state how unknown or missing responses were handled.
Worked Examples
Worked Example: Coding a Yes/No Response
Hypothetical data. A training program asks eight participants, “Did you attend the optional review session?” The recorded answers are Yes, No, Yes, Unknown, Yes, No, Yes, and Yes. The question has two definite substantive answers, Yes and No. Before recoding, the code map is written as 0 = No and 1 = Yes; Unknown is not assigned either value.
| Participant | Recorded answer | Encoded value |
|---|---|---|
| 01 | Yes | 1 |
| 02 | No | 0 |
| 03 | Yes | 1 |
| 04 | Unknown | Missing |
| 05 | Yes | 1 |
| 06 | No | 0 |
| 07 | Yes | 1 |
| 08 | Yes | 1 |
Check the counts. There are five Yes answers, two No answers, and one Unknown answer. The encoded variable therefore has five 1s, two 0s, and one missing value. The number of valid binary responses is \(5+2=7\), not 8.
If a summary of the valid responses is useful, the fraction coded 1 is
This means that 5 of the 7 participants with a definite Yes or No answer reported attending. It does not mean 5 of all 8 participants attended: one answer was unknown. The denominator and the coding definition are both needed for an accurate interpretation.
Worked Example: Choose and Document a Coding Direction
Hypothetical data. A small clinic records whether each of nine people received a reminder before an appointment. The responses are Received, Not received, Received, Not received, Received, Received, Not received, Not received, and Not recorded. For the binary variable reminder_received, define 0 = Not received and 1 = Received. Not recorded is not evidence that no reminder was received.
The eight recorded substantive answers comprise four Received and four Not received responses. The ninth response is Not recorded, so it remains missing for the binary variable. A count check is
The encoded data should contain four 1s and four 0s among those eight valid responses, plus one missing value. As a check, the fraction of valid responses coded 1 is
Thus half of the people with a recorded Received/Not received answer had received a reminder. This result describes the valid recorded answers; it does not classify the person whose response was Not recorded. The map also makes the variable's meaning explicit: someone reading a 1 can identify it as Received rather than having to infer the coding direction.
Worked Example: Keep “Unknown” Separate From “No”
Hypothetical data. A questionnaire asks whether a participant has a family history of a condition. Its stored responses use source codes 1 = Yes, 2 = No, 7 = Not asked, and 9 = Do not know. Suppose ten records contain four 1s, four 2s, one 7, and one 9.
For a binary analysis variable, choose the explicit map 0 = No and 1 = Yes. Recode source code 2 to 0 and source code 1 to 1. Neither 7 nor 9 is a Yes/No answer, so neither becomes 0 or 1. Both are missing for the binary variable, but their original source values or response-status labels should be retained so that “Not asked” can still be distinguished from “Do not know.”
The valid binary count is
Among the eight participants who answered Yes or No, half answered Yes. The other two records do not count as No: one was not asked the question, and one did not know the answer. Keeping their status visible avoids turning absence of a definite Yes into a false No.
Why the 0/1 Mean Can Be Useful
When a binary variable is coded 0 = No and 1 = Yes, its mean among valid responses equals the fraction of valid responses that are Yes. This identity is a quick check and can be useful when summarizing a binary variable. It does not turn the categories into a quantitative measurement; the mean has a particular proportion interpretation because of the chosen coding.
To see why, let \(n\) be the number of valid responses, and let \(k\) be the number coded 1. Each of the remaining \(n-k\) valid responses is coded 0, so the sum of the codes is \(k(1)+(n-k)(0)=k\). The mean is therefore
The derivation depends on having only valid 0s and 1s in the calculation. If an unknown response is mistakenly coded 0, the calculated fraction becomes the fraction of all records not known to be Yes, which is not generally the same as the fraction of valid answers that are No. Always check how the denominator was formed.
Validation and Common Pitfalls
After recoding, inspect the values and reconcile their counts with the original answers. For a variable intended to contain only 0 and 1, any other number is a signal to investigate, not a value to interpret automatically. Compare each mapped category with its recorded label; if an answer cannot be matched confidently to either category, leave it flagged for clarification rather than guessing. Keep the code map with the prepared data.
- Using 0 for every answer other than Yes. This silently turns Unknown, blank, and Not asked into No. Map only the defined No response to 0; preserve other statuses separately or mark them missing for the binary variable.
- Assuming 1 always means Yes. A coding direction is a choice, not something a reader can infer from the numeric value. Document the meaning of both codes.
- Calling the code a measurement. A value of 1 does not mean “one unit more” than 0. These numbers label categories. With a documented 0/1 scheme, the mean can represent a proportion, but other arithmetic interpretations do not follow.
- Ignoring the denominator. A proportion calculated from valid answers differs from a calculation that includes records with unknown or unanswered responses. State which records were counted.
Check Your Understanding
Answer each question using an explicit code map and a clear denominator where needed.
- A survey response is Yes, No, or Not sure. If the analysis variable is intended to represent definite Yes/No answers, how should Not sure be handled?
- For a variable coded 0 = No and 1 = Yes, a data set has 6 Yes answers, 3 No answers, and 1 unanswered record. What is the fraction coded 1 among valid responses?
- Why is it not enough to state that a variable has values 0 and 1?
- A source file records “Not asked” using a special source response. Explain why recoding it as 0 could be misleading.
- What does the mean of a valid 0/1 variable represent when 1 is explicitly defined as Yes?