The Economist Style Guide gives the following distinction to be used when writing (or at least, writing for The Economist - not a bad baseline to use):

Gender is a word applied to grammar, not to people. If someone is female, that is her sex, not her gender

Source: The Economist Style Guide. Natch.