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

st: Check if variables have same value

From   "Friedrich Huebler" <>
Subject   st: Check if variables have same value
Date   Fri, 27 Jul 2007 12:31:38 -0400

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:

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