Dear Statalisters:
I apologize if this has been asked somewhere and already answered but I don't know where to begin with this one.
I have a list of nine possible values for Variable Y. It's an occupation code where, for example, 1=CEO, 2=Manager, etc. A person can hold up to 9 possible jobs, hence there are 9 variables (y_1, y_2, y_3...y_9).
I also have a list of nine possible values for Variable X. Variable X could be any number of things, although hourly rate of pay or number of hours worked at this job are two possibilities. As a person can hold up to 9 possible jobs, there are 9 variables here too (x_1, x_2...x_9).
Here's what I want to do: I want to create a single variable (Variable Z) equal to the value from Variable Y that has the highest value of Value X.
So, for example, let's say a person held 9 jobs, where they were paid between $11 to $19 per hour (with x_9 being the $19 / hour one). I would want that person to have Z=y_9.
Another example: If a different person held 9 jobs, where they were paid between $21 and $29 per month (with x_6 being the $29 / hour one), then I want that person to have Z=y_6.
I know how to do this if I wanted Variable Z to be equal to the highest value of X, using egen and rowmax. I don't know how to do it if I want Z to equal the Y with the highest value of X.
Has anyone figured out an easy solution to this? Thank you in advance.
I apologize if this has been asked somewhere and already answered but I don't know where to begin with this one.
I have a list of nine possible values for Variable Y. It's an occupation code where, for example, 1=CEO, 2=Manager, etc. A person can hold up to 9 possible jobs, hence there are 9 variables (y_1, y_2, y_3...y_9).
I also have a list of nine possible values for Variable X. Variable X could be any number of things, although hourly rate of pay or number of hours worked at this job are two possibilities. As a person can hold up to 9 possible jobs, there are 9 variables here too (x_1, x_2...x_9).
Here's what I want to do: I want to create a single variable (Variable Z) equal to the value from Variable Y that has the highest value of Value X.
So, for example, let's say a person held 9 jobs, where they were paid between $11 to $19 per hour (with x_9 being the $19 / hour one). I would want that person to have Z=y_9.
Another example: If a different person held 9 jobs, where they were paid between $21 and $29 per month (with x_6 being the $29 / hour one), then I want that person to have Z=y_6.
I know how to do this if I wanted Variable Z to be equal to the highest value of X, using egen and rowmax. I don't know how to do it if I want Z to equal the Y with the highest value of X.
Has anyone figured out an easy solution to this? Thank you in advance.
Comment