[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: Simple recoding
a simple (and stupid) way to do is:
gen gender=1 if sex=="M"
mvencode gender, mv(2)
or you can use the smarter flashier command _recode_
but i am not sure how to use that. i think you can:
recode sex "M"="1"
recode sex "F"="2"
destring sex, replace
one thing to note is that your variables must carry numerical values only
when you destring them.
University of Newcastle upon Tyne Business School
> I have a variable in my datasheet, sex which is formatted as str1 %9s.
> There are two types either M or F. I need to convert this so that M=1 and
> F=2. How do I do this, or where is a problem similar to this described. I
> have tried using "destring sex, replace" etc but have had no luck.
> Thanks for all your help in advance on this relatively simple question.
* For searches and help try: