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?

 A: 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").

A: 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. 
A: 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.
A: 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.
A: 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.
A: 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.
A: 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();
}

