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

st: RE: RE: gen new variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: gen new variable
Date   Mon, 21 Oct 2002 12:47:43 +0100

Kompal Sinha 

> > I want to generate a new variable based on a variable x. 
> That is the new
> > variable should have value 1 if x=2, value 6 if x=3 and 
> so on. How do I
> > proceed.

I don't know what you mean by "and so on". I can't 
see a pattern in these rules, but you can use 
as many steps as it takes: 

gen new = 1 if x == 2 
replace new = 6 if x == 3
replace new = ... if x == ... 

An alternative with just integers is to copy x 
to a new variable and use -recode-. 

Nick 
n.j.cox@durham.ac.uk 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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