Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Assigned sex
From
Austin Nichols <[email protected]>
To
[email protected]
Subject
Re: st: Assigned sex
Date
Tue, 28 Dec 2010 18:35:18 -0500
Phil, Amal--
Some caution about unexpected values is always in order, esp. a string
indicating a missing value:
clear
input str1 sex
M
F
U
.
end
label define male 0 "F" 1 "M"
encode sex, label(male) gen(male)
g m=sex=="M" if inlist(sex,"M","F")
list
list, nol
On Wed, Dec 22, 2010 at 8:08 AM, Phil Clayton
<[email protected]> wrote:
> Use -encode- to convert the sex variable to a numeric one, eg:
>
> label define male 0 "F" 1 "M"
> encode sex, label(male) gen(male)
>
> Note that I've made the values 0 and 1, rather than 1 and 2, because this makes "male" a dummy variable suitable for regression.
>
> Phil
>
> On 22/12/2010, at 11:50 PM, Marcello Pagano wrote:
>
>>
>> -------- Original Message --------
>>
>> Dear stata-listers,
>>
>> 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.
>> The variable looks like this:
>>
>> . sum sex
>>
>> Variable | Obs Mean Std. Dev. Min Max
>> -------------+--------------------------------------------------------
>> sex | 0
>>
>> . tab sex
>>
>> c:sex | Freq. Percent Cum.
>> ------------+-----------------------------------
>> F | 584 48.50 48.50
>> M | 620 51.50 100.00
>> ------------+-----------------------------------
>> Total | 1,204 100.00
>>
>> 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?? And the number
>> of observations will be listed as 1,204 when the variable is summarized?
>>
>> As of now the varibale is the 'str1' format.
>>
>> Thanks!
>> Amal Khanolkar, PhD candidate,
>> Centre for Health Equity Studies (CHESS),
>> Karolinska Institutet,
>> 106 91 Stockholm.
*
* 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/