Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: compare variables


From   "Neil Shephard" <[email protected]>
To   [email protected]
Subject   Re: st: compare variables
Date   Thu, 30 Aug 2007 09:45:48 +0100

> 2007/8/30, Stat List <[email protected]>:
> > Hi Statalist,
> >
> > If I have two variables with numeric contents, is there any Stata command to
> > compare them, and get the maximum into another variables?
> >
> > Example, comparing (elements by elements) var1 and var2, and then creating
> > var3=max(var1, var2)
> >
> > Var1 var2 var3
> > 12      32      32
> > 21      12      21
> > 3       32      32
> > 32      12      32
> > ..      ..      ..
> >
> > I think  I can write the loop for all observations, but I think that Stata
> > have this kind of command that I just don't know yet.
> >
> > Any help? Thanks so much

You can do this directly using the -egen- command.

egen var3 = rowmax(var1 var2)

-egen- is a very useful command see...

Cox N.J. (2002) Speaking Stata:  On getting functions to do the work.
The Stata Journal 2(4):411-427

...for details on how to get things done with -egen- and more
generally with -functions-.

Neil
-- 
"In mathematics you don't understand things. You just get used to
them."  - Johann von Neumann

Email - [email protected] / [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index