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]
st: RE: generate a new categorical variable
From
"Sarah Edgington" <[email protected]>
To
<[email protected]>
Subject
st: RE: generate a new categorical variable
Date
Thu, 13 Sep 2012 13:32:23 -0700
Your code looks like it should work.
My first thought is that you should double check that the data really looks
like what you expect. I'd start with a cross-tabulation of Y and Z. For
your code to work it has to be true that Y==1 when Z takes the B, C, and D
values. Likewise, you want to be sure that you have all the values for Z
(and that they're capitalized as shown and don't include spaces).
-Sarah
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of urbain thierry
YOGO
Sent: Thursday, September 13, 2012 12:54 PM
To: [email protected]
Subject: st: generate a new categorical variable
Dear all
i have two variables Y and Z. Y is a dummy variable which takes 1 if
individual has access to water and 0 otherwise. Z is a categorical variable
which has the following structure:
Z=A if individual uses bleach to clean water Z=B if individual use a filter
to clean water Z=C if individual use solar energy to clean water Z=D if
individual use absorbent cotton to clean water
Here is my problem. I want to generate a new variable X which should be a
combination of Y and Z. Here is the code i have written gen X=0 if Y==0
replace X=1 if Y==1 & Z=="A"
replace X=2 if Y==1 & Z=="B"
replace X=3 if Y==1 & Z=="C"
replace X=4 if Y==1 & Z=="D"
My concern is that when i write this code, the first two lines work, but
after, there is 0 replacement. Please can somebody help me? Thank
--
*Urbain Thierry YOGO
Ph.D candidate in Economics*
*
* 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/
*
* 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/