max - Get the variable name that corresponds to the maximum value within an observation -
i need find variable name corresponds highest value in each observation given variable list. know can utilize egen
value itself:
egen newvar = rowmax(v1-vn)
but don't know how variable name corresponding highest value.
there might other ways, can build on egen
results. here illustration looping through variables find variable(s) maximum values.
// generate random info clear set obs 10 forval i=1/5 { gen r`i'=round(10*runiform()) } egen maxval=rowmax(r1-r5) // find maximum value gen str20 maxvar="" // create string variable store matched results // find variables same value maxval , add together them maxvar foreach var of varlist r1-r5 { replace maxvar=maxvar+" "+"`var'" if maxval==`var' } list
max stata
No comments:
Post a Comment