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]
Re: st: Assigned sex
Maarten buis <firstname.lastname@example.org>
Re: st: Assigned sex
Wed, 22 Dec 2010 13:21:22 +0000 (GMT)
Maarten L. Buis
Institut fuer Soziologie
--- 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 ---------------
input y str7 sex
gen female = cond(sex=="F", 1, ///
cond(sex=="M", 0, .))
*----------- end example ------------------
(For more on examples I sent to the Statalist see:
(The last respondent in the example was probably not being
serious, such things also happen in real data.)
Hope this helps,
* For searches and help try: