Austin's solution is fine. Just for reference an alternative is
cond(tob < pok, 1, cond(tob > pok, 2, 3)) if !mi(tob, pok)
but I judge Austin's solution to be more direct.
A different issue is why are you coding < == > as 1 3 2
not 1 2 3 or 3 2 1?
Nick
[email protected]
Austin Nichols
> g risk=(tob<pok)+2*(tob>pok)+3*(tob==pok) if !mi(tob,pok)
Krista Richard
> > I'm new to stata and I need help to recode two variables
> into one. I'm not
> > succeeding so I'm hoping someone will be able to help me out.
> >
> > I have two variables:
> >
> > age at first poker use (poker) and age of first tobacco use
> (tobacco).
> >
> > I want to create a variable (risk_behaviour) with 3 levels
> that will have
> > the value labels of 1 = tobacco<poker, 2 = tobacco>poker, and 3
> > tobacco=poker. I run into trouble with this as stata is treating my
> > missing values when it calculates it and I can't seem to make it not
> > compute this when either original variable has missing values.
*
* 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/