Hello,
I have 1200 observations for which I'm trying to find: a) the min value among some 30 variables and; b) which variable was this with the minimum value.
My dataset looks like this:
I can find the min value among a b c using:
However, I'm having trouble determining which variable was the one with the minimum value. Please note that there are cases (such as with id == 7) in which the minimum value is equal among two different variables. Ideally, the code should return this:
Any ideas on how to obtain this?
I have 1200 observations for which I'm trying to find: a) the min value among some 30 variables and; b) which variable was this with the minimum value.
My dataset looks like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id a b c) 1 .1 .2 .3 2 .2 .3 .4 3 .4 .1 .4 4 .3 .37 .5 5 .2 .4 .22 6 .3 .5 .6 7 .1 .3 .1 end
Code:
egen min = rowmin(a b c)
Code:
+--------------------------------------+ | id a b c min whichvar | |--------------------------------------| 1. | 1 .1 .2 .3 .1 a | 2. | 2 .2 .3 .4 .2 a | 3. | 3 .4 .1 .4 .1 b | 4. | 4 .3 .37 .5 .3 a | 5. | 5 .2 .4 .22 .2 a | |--------------------------------------| 6. | 6 .3 .5 .6 .3 a | 7. | 7 .1 .3 .1 .1 a c | +--------------------------------------+
Comment