Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Simple recoding

From   "Ada Ma" <>
To   <>
Subject   st: Re: Simple recoding
Date   Fri, 16 Aug 2002 13:09:09 +0100

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.

Ada Ma
University of Newcastle upon Tyne Business School
Economics Group wrote:
> 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:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index