# Why is gender typically coded 0/1 rather than 1/2, for example?

I understand the logic of coding for data analysis. My question below is on the use of a specific code.

• Is there a reason why gender is often coded as 0 for female and 1 for male?
• Why is this coding considered 'standard'?
• Compare this with Female = 1 and Male = 2. Is there a problem with this coding?
• Using a 0/1 coding scheme is essentially useful when applying regression models among others, although several coding schemes are possible, e.g. -1/1 (but it will change the interpretation of the regression coefficients). It should not be confused with data entry (that is, what you really put in your database), though. In this case, it is better to store the full labels. Convert them to numerical values or build a dedicated design matrix when you build your regression model. Otherwise, I wish you good luck to tell what the 0 and 1's stand for in 5 years. – chl Oct 7 '11 at 21:11
• I've seen the gender coded in the database as male, female and unknown. – Aksakal May 18 '15 at 18:20
• I think this question is best considered as two questions confounded. The larger question is why use 0-1 coding rather than any other for an indicator or dummy variable. The smaller question is why use 1 for male and 0 for female, to which one short answer is that many other codings are in use, including the opposite of 1 for female, etc., and also various complex codings allowing for unknown gender and for other gender categories. – Nick Cox May 18 '15 at 18:34

### Reasons to prefer zero-one coding of binary variables:

• The mean of a zero-one variable represents the proportion in the category represented by the value one (e.g., the percentage of males).
• In a simple regression $y = a + bx$ where $x$ is the zero-one variable, the constant has a straightforward interpretation (e.g., $a$ is the mean of $y$ for females).
• Any coding of a binary variable where the difference between the two values is one (i.e., zero-one, but also one-two) gives a straightforward interpretation to the regression coefficient (e.g., $b$ is the effect of going from female to male on y).

### Assorted points about coding binary variables:

• Any coding of a binary variable that preserves the order of the categories (e.g., female = 0, male = 1; female = 1, male = 2; female = 1007, male =2000; etc.) will not affect the correlation of the binary variable with other variables.
• Any tables that report a binary variable in this way should make it clear how the variable was coded. It can also be useful to label the variable by the category that represent the value of one: e.g., y = a + b * Male rather than y = a + b * Gender.
• For some binary variables, one category more naturally should be coded as one. For example, when looking at the difference between treatment and control, control should be zero, and treatment should be one, because the regression coefficient is best thought of as the effect of the treatment.
• Flipping the categories (e.g., making female = 1 and male = 0, rather than female = 0 and male = 1) will flip the sign of correlations and regression coefficients.
• In the case of gender, there is typically no natural reason to code the variable female = 0, male = 1, versus male = 0, female = 1. However, convention may suggest one coding is more familiar to a reader; or choosing a coding that makes the regression coefficient positive may ease interpretation. Also, in some contexts, one gender may be thought of as the reference category; for example, if you were studying the effect of being female in a male dominated profession on income, it might make sense to code male = 0, and female = 1, in order to speak of the effect of being female.
• Scaling regression coefficients in thoughtful ways can have a powerful effect on the interpretability of regression coefficients. Andrew Gelman discusses this quite a bit; see for example his 2008 paper Scaling regression inputs by dividing by two standard deviations (PDF) in Statistics in Medicine, 27, 2865-2873.
• Coding male and female as -1 and +1 is another option that can provide meaningful coefficients (see "what is effect coding").
• Uh, I always thought the natural reason to code female = 0 and male = 1 was "anatomy"... – Matt Parker Oct 7 '11 at 23:39
• @matt funny. I'd never thought of it like that. I'd always been influenced by the lens of my Arts degree, where you are taught about how some feminists critique ideologies that see females defined by the lack of something possessed by males. Through such a lens, somewhat humorously, the coding of gender becomes a political issue :-) – Jeromy Anglim Oct 8 '11 at 0:03
• As a habit, I always change a gender variable name to something like "Female", to make it clear what a 0/1 coding scheme means. – Fomite Oct 8 '11 at 21:12
• Jeromy, will you want to observe the discussion stats.meta.stackexchange.com/a/4881/3277 of whether we need a separate tag [dummy-variables] and say your pro/con in a comment? – ttnphns Jul 29 '17 at 9:11
• Considering the pair of sex chromosomes X and Y, females have XX and males have XY chromosomes. Taking X=0 and Y=1, we can find that female=XX=00=0 and male=XY=01=1. – Gürol Canbek Dec 30 '18 at 20:50

It makes it easier to interpret the results. Suppose you had some height data:

Woman A: 165
Woman B: 170
Woman C: 175
Man D: 170
Man E: 180
Man F: 190

and you took a regression of the form Height = a + b * Gender + Residual.

With the 0,1 dummy variable you would get an estimate of a of 170 being the average height of the women and of b of 10 being the difference between the average heights of the men and the women.

With the 1,2 dummy variable you would get an estimate of a of 160 which is harder to interpret.

• Thanks. I am learning statistics at the 'speed of light' because it is a requirement of my new job. Would this coding still apply to correlation analysis. – Adhesh Josh Oct 7 '11 at 20:52
• @Adhesh If you mean correlation between two quantitative variables, then there's no coding issue: just use the raw measures. If your question is about association between two qualitative variables, then you might consider asking a new question, but frankly there's not much difficulty in this case (unless you want to use unevenly spaced scores for variables categories, but this has been answered elsewhere on this site). – chl Oct 7 '11 at 21:04
• @Adesh Coding a binary 1/2 or 0/1 will get you not affect your correlation coefficient. 0/1 also has the advantage that the mean of the variable would be the percent male or female, depending on which is which. Other coding schemes may be useful for interpreting different types of analysis. – Michael Bishop Oct 7 '11 at 21:16

I had assumed that this was because the field type often used to store gender is a bit field, and bit fields in SQL can only have the values 0 or 1. When you dump out the data, it comes out as 0 or 1, and so that's why you get those particular values.

If you wanted to use 1 and 2, you'd have to use a bigger field type, which would take up more space, and thus make the whole database slightly bigger.

• As a SQL programmer this was my first reaction as well. I'm not sure about any pure mathematical reasons for using 0 and 1 for gender, but I know for a fact that some of the impetus came from the need to use the smallest data types possible. Industry-wide standards were developed from custom and everyone fell in line. It may be worthwhile to check ANSI standards history for this. These days there's a push to get DBAs to use byte or small integer columns for gender, to indicate unusual exceptions like "corporate entity" or "indeterminate" but many old databases still reflect the old standard. – SQLServerSteve Feb 20 '16 at 20:28

I had a professor suggest that we code "biologically" with women being 0 and men being 1 - to reflect anatomy. I don't think it was the most sensitive, or PC thing to say in a class, but definitely easy to remember when looking at a dataset 5 years later.

• This clearly isn't the "real" answer to the question (perhaps this is more of a comment than an answer), but the mnemonic is clearly one that a lot of people find useful. – Silverfish Feb 20 '16 at 20:19
• More "biological" than "anatomical", I was taught (though I suspect the "reason" was invented in retrospect, rather than being the original) that 0 is used for female as it's the "default" sex - the belief being that in embryological development, the female pathway is taken unless intervening processes push the embryo to differentiate down the male pathway. This was once a widespread belief, but is now considered outdated: the female pathway also needs to be actively triggered. – Silverfish Feb 20 '16 at 20:23
• In this case, shouldn't men be coded as "00". – Harvey Motulsky Feb 21 '16 at 2:29

Many good reasons posted so far, but it should also be reflexive. Why would you start counting at 1? It makes lots of numerical algorithms far more complicated. Labeling begins at 0, not 1. If you're not yet convinced of this, I have a nice example of why it's important at http://madhadron.com/?p=69

As for why women are 0 and men are 1, let's remember that for much of its history, a statistician was likely to be a straight male. When asked to name a sex, the first one to come to mind was 'woman'. Everything after that was probably historical accident and rationalization.

The ISO/IEC 5218 standard updates this notion with the following map:

0 = not known,
1 = male,
2 = female,
9 = not applicable.

This is particularly useful in languages where 0 coerces to a false value, such as in JavaScript:

if ( !user.gender ) {
promptForGender();
}
• It is important to note that this kind of standard is really for data transmission and/or storage. It is not adequate as a standard for data analysis, which is what the question is specifically about. – whuber May 18 '15 at 17:11

The way I see it personally is phallically 0 typically represents female, as it is the shape of the womb, and considered to be feminine...in almost all sciences (i.e. in biology/genetics pedigree charts) circles, or zeros represent females. Where as more straight edge shapes (triangles, squares, or 1s) tend to represent the male gender. This simple understanding has made it easy to always remember which is which for me.

Although at the end of the day if you are the one coding and analyzing the data yourself you can put whatever numbers you want, generally as long as there is a key as to which dummy variable you used for which, it becomes irrelevant.

• Strange answer to a silly question. – Michael Chernick May 15 '18 at 16:17

## protected by kjetil b halvorsenMay 15 '18 at 16:38

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).