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

Re: st: Check if variables have same value

From   Jeph Herrin <>
Subject   Re: st: Check if variables have same value
Date   Fri, 27 Jul 2007 14:11:05 -0400


Friedrich Huebler wrote:
Thank you, this solution works for numeric variables. Do you have any
suggestions for strings?


On 7/27/07, Jeph Herrin <> wrote:
Why not

  . egen rowmin=rowmin(var1 var2 ... varN)
  . egen rowmax=rowmax(var1 var2 ... varN)
  . gen tag=rawmax!=rowmin

? -rowmin- and -rowmax- ignore missing values.


Friedrich Huebler wrote:
I would like to compare a set of variables and tag those that do not
contain the same values. Missing values should be ignored. -egen
newvar = diff(varlist)- is not an option because it does not skip
missing values. The last command in the example below works but it
becomes impractical with a longer list of variables.

. sysuse auto
. gen mpg2 = mpg if foreign==0
. gen mpg3 = mpg if foreign==1
. replace mpg3 = mpg+1 if rep78==2
. egen tag = diff(mpg mpg2 mpg3)
. gen tag2 = (mpg!=mpg2 & mpg<. & mpg2<. | mpg!=mpg3 & mpg<. & mpg3<.
| mpg2!=mpg3 & mpg2<. & mpg3<.)

The -egen- command tags all observations, the -gen- command only those
that I expect to be tagged. Are there better solutions that can also
be used with ten or more variables?

*   For searches and help try:

*   For searches and help try:

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