Hello everybody,
I am working on a dataset in which there is a number of variables reporting to distance between the obs position and a specific party position on a given issue. Each column corresponds to a specific political party and in each cell I have the difference between the obs and the party. Now, I want to generate a variable recording the min value among those that are available in each row and a new variable in which I record the name of the party that is the closest one to the obs. I tried to run this command:
egen min=rowmin(distance*) > gen min_var = "" > foreach v of varlist distance* { > replace min_var = "`v'" if `v' == min > } Indeed, it works, but it does not handle with ties. How to deal with the situation in which the min differences for one specific observation are the same? Thank you Davide
I am working on a dataset in which there is a number of variables reporting to distance between the obs position and a specific party position on a given issue. Each column corresponds to a specific political party and in each cell I have the difference between the obs and the party. Now, I want to generate a variable recording the min value among those that are available in each row and a new variable in which I record the name of the party that is the closest one to the obs. I tried to run this command:
egen min=rowmin(distance*) > gen min_var = "" > foreach v of varlist distance* { > replace min_var = "`v'" if `v' == min > } Indeed, it works, but it does not handle with ties. How to deal with the situation in which the min differences for one specific observation are the same? Thank you Davide
Comment