Have a panel dataset of the following form, where t is time variable and id is panel variable.
t id x y z
1 1 2 0 1
1 2 2 0 6
1 3 5 0 3
2 1 0 0 4
2 2 2 1 7
2 3 0 2 1
Trying to generate a new variable, a, that looks across rows in variables x, y and z, evaluates the maximum value and generates the name of the variable in which that maximum exists to get the below output.
t id x y z a
1 1 2 0 1 x
1 2 2 0 6 z
1 3 5 0 3 x
2 1 0 0 4 z
2 2 2 1 7 z
2 3 0 2 1 y
Evaluating the maximum part is pretty straightforward ( e.g. gen a = max(x, y, z) ), but getting stata to return the name of the variable has me stumped.
Thanks
Alban
t id x y z
1 1 2 0 1
1 2 2 0 6
1 3 5 0 3
2 1 0 0 4
2 2 2 1 7
2 3 0 2 1
Trying to generate a new variable, a, that looks across rows in variables x, y and z, evaluates the maximum value and generates the name of the variable in which that maximum exists to get the below output.
t id x y z a
1 1 2 0 1 x
1 2 2 0 6 z
1 3 5 0 3 x
2 1 0 0 4 z
2 2 2 1 7 z
2 3 0 2 1 y
Evaluating the maximum part is pretty straightforward ( e.g. gen a = max(x, y, z) ), but getting stata to return the name of the variable has me stumped.
Thanks
Alban
Comment