Dear Statalist,
I have data on cropped area for 11 different crops (variables) in 500 districts of India (observations). I am trying to rank each crop according to its area within each district, in order to determine the most cultivated crop, second most cultivated crop, third most... etc. Using the code below, I generated a new variable that holds the highest value of all crops for each observation:
unab xvars: rice wheat crscereals maize pulses oilseeds sugarcane cotton fruitsveg rootstubers fodder
local xarg : subinstr local xvars " " ",", all
generate xmax = max(`xarg')
But I do not know for which crop this value is given. Is there a way to return the variable name rather than value??
Also, is there a way to identify the second highest value/variable? and third highest?
I was able to do something similar in excel and ArcGIS using a conditional statement, but the intuition is not clear here.
Thank you!!!
Hilary
I have data on cropped area for 11 different crops (variables) in 500 districts of India (observations). I am trying to rank each crop according to its area within each district, in order to determine the most cultivated crop, second most cultivated crop, third most... etc. Using the code below, I generated a new variable that holds the highest value of all crops for each observation:
unab xvars: rice wheat crscereals maize pulses oilseeds sugarcane cotton fruitsveg rootstubers fodder
local xarg : subinstr local xvars " " ",", all
generate xmax = max(`xarg')
But I do not know for which crop this value is given. Is there a way to return the variable name rather than value??
Also, is there a way to identify the second highest value/variable? and third highest?
I was able to do something similar in excel and ArcGIS using a conditional statement, but the intuition is not clear here.
Thank you!!!
Hilary
Comment