Just smaller than any value that occurs in the variables concerned.
-
Login or Register
- Log in with
clear
set obs 10
set seed 2803
local var = 0
local ind = 0
while `var' <= 1000000 {
local ++ind
local var = `var' + ( 1000000 * 0.01 )
forval j = 1/5 {
gen x`j'`var' = ceil(100 * runiform()) * `var'
}
gen which_max`var' = ""
gen max`var' = 0
unab xvars : x*
quietly foreach x of local xvars {
replace which_max`var' = "`x'" if `x' > max`var'
replace max`var' = `x' if `x' > max`var'
}
quietly foreach x of local xvars {
gen new`x'`var' = `x' == max`var'
}
}
unab xvars : x*
while `var' <= 1000000 {
local ++ind
local var = `var' + 10000
local xvars
forval j = 1/5 {
gen x`j'`var' = ceil(100 * runiform()) * `var'
local xvars `xvars' x`j'`var'
}
gen which_max`var' = ""
gen max`var' = 0
quietly foreach x of local xvars {
replace which_max`var' = "`x'" if `x' > max`var'
replace max`var' = `x' if `x' > max`var'
}
quietly foreach x of local xvars {
gen new`x'`var' = `x' == max`var'
}
}
clear
set seed 2803
set obs 7
forval j = 1/5 {
gen y`j' = ceil(12 * runiform())
}
list
gen id = _n
sort id
save myorigdata, replace
reshape long y, i(id)
gsort id -y
by id: gen rank = _n
rename _j which
drop y
reshape wide which, i(id) j(rank)
list
sort id
merge 1:1 id using myorigdata
unab xvars: rice wheat crscereals maize pulses oilseeds sugarcane cotton fruitsveg rootstubers fodder
gen which_max = ""
gen max = 0
quietly foreach x of local xvars {
replace which_max = "`x'" if `x' > max
replace max = `x' if `x' > max
}
gen which_min = ""
gen min = .
quietly foreach x of local xvars {
replace which_min = "`x'" if `x' < min
replace min = `x' if `x' < min
}
quietly foreach x of local xvars {
replace which_min = "`x'" if `x' <= min
replace min = `x' if `x' < min
}
quietly foreach x of local xvars {
replace which_min = "`x'" if `x' < min
replace which_min = which_min + " `x'" if `x' == min
replace min = `x' if `x' < min
}
* Example generated by -dataex-. To install: ssc install dataex clear input float(tot_wethos_1rough90 tot_wethos_2emerg90 tot_wethos_3temp90 tot_wethos_6institution90 tot_wethos_7support90) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . 3 . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . end
Comment