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

st: RE: joining variables


From   "Nick Winter" <nwinter@policystudies.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: joining variables
Date   Wed, 19 Feb 2003 16:29:36 -0500

> -----Original Message-----
> From: Sophie Barthel [mailto:sophie@stats.ucl.ac.uk] 
> Sent: Wednesday, February 19, 2003 4:09 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: joining variables
> 
> 
> 
> Dear List
> 
> I have got the following problem:
> 
> From a set of observations I have created a variable to10la for people
> whose left eye was measured and a variable to10ra for people 
> whose right
> eye was measured. Whenever a person appears in the data whose 
> right eye
> was measured to10la displays a missing value and vice versa. All of
> these are meant to be merged into one variable, however I do 
> not seem to
> be able to find out how to do this.
> 
> Thank you
> 
> Sophie

You have a couple of options.

Assuming that each person appears only once, and that each person has
only one rating (eihter right or left, not both), then:

	. gen rating = to10ra 
	. replace rating = tot10la if rating>=.

Or, equivalently

	. egen rating=rmax(to10ra to10la)

which gives you the maximum of the two variables (ignoring blanks).  You
would get the same thing with

	. egen rating=rmin(to10ra to10la)

or with

	. egen rating=rmean(to10ra to10la)

If some cases have both ratings, then you could use one of the -egen-
statements, depending on how you wanted to combine the two.

If you might have multiple records for an individual (one with a left
rating, the other with a right rating), then you should -reshape- the
data first.

Nick Winter


*
*   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