Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Maarten buis <maartenbuis@yahoo.co.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Assigned sex |

Date |
Wed, 22 Dec 2010 13:21:22 +0000 (GMT) |

-------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- --- On Wed, 22/12/10, Amal wrote: > I would like some help is using the 'recode' command (or > any other appropriate one) to reformat one of my variables. > > The variable 'sex' describes what sex each of my subjects > is assigned to. <snip> > As you can see the above variable isn't particularly useful > for regression, and basic statistics that I would like to > use it for. How would I somehow recode the variable, such > that all boys are coded as 1 and girls as 2?? It is almost always a bad idea to code such a variable 1=male, 2=female. If you instead code it 0=male, 1=female a lot of things will become a lot easier. The mean of such a variable equals the proportion of females. In a regression the constant will represent males, while in the 1,2 coding the constant represents some unknown third sex. Interaction effects become much much easier to interpret when you code your variable 0,1. You can call that variable female, and you can use the convention that 1 equals "true" and 0 "false". To transform your variable from a string to a numerical variable you could use -encode- but for some reason I never use it, and instead I tend to do that manually. I find it easier and the code easier to read, but that is probably only because I am used to doing it that way. For doing it manually the -cond()- function is often very helpful, see -help cond()-. *---------- begin example --------------- clear input y str7 sex 1 "F" 2 "F" 1 "F" 3 "M" 2 "M" 200 "Klingon" end gen female = cond(sex=="F", 1, /// cond(sex=="M", 0, .)) list, clean *----------- end example ------------------ (For more on examples I sent to the Statalist see: http://www.maartenbuis.nl/example_faq ) (The last respondent in the example was probably not being serious, such things also happen in real data.) Hope this helps, Maarten * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Assigned sex***From:*Marcello Pagano <pagano@hsph.harvard.edu>

- Prev by Date:
**Re:st:any easy alternative way when -egen- is not allowed to combine** - Next by Date:
**Re: st:any easy alternative way when -egen- is not allowed to combine** - Previous by thread:
**Re: st: Assigned sex** - Next by thread:
**st: -romantoarabic- now available from SSC** - Index(es):