Dear Stata Users,
Using -rowmax()- of egen function, we can find the maximum value in varlist for each observation (row). And now I want to find the second maximum value besides the first in each row. Is there any way to solve the problem? Commands and data example are as follows. Thank you.
Using -rowmax()- of egen function, we can find the maximum value in varlist for each observation (row). And now I want to find the second maximum value besides the first in each row. Is there any way to solve the problem? Commands and data example are as follows. Thank you.
Code:
egen firstmax=rowmax(h1a h1b h1c h1d h1e h1f h1n h1o h1p h1q)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long(h1a h1b h1c h1d h1e h1f) int h1g long h1h int h1i long h1j int h1k long h1l int h1m long(h1n h1o h1p h1q) 40000 2000 0 0 20000 0 0 2000 0 3000 0 300 0 7000 0 0 0 0 3000 0 1000 0 0 0 0 0 0 2220 325 0 0 0 0 0 0 50000 0 0 0 0 0 0 0 0 0 900 0 0 0 0 20000 30000 15000 0 0 0 0 0 0 0 2500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50000 0 0 50000 0 36500 2000 0 0 0 0 3420 0 0 960 0 0 0 0 1500 30000 0 0 0 0 0 0 0 0 0 1600 0 1000 0 0 0 50000 0 0 0 0 0 0 0 0 30000 1200 0 3600 0 0 0 0 60000 30000 0 0 0 0 0 0 0 10000 0 630 10000 10000 0 0 5500 70000 0 0 0 500 0 0 1500 0 0 0 0 0 0 0 0 0 20000 4000 0 0 0 0 0 5000 0 2400 0 500 0 1000 0 0 0 6000 5500 0 0 0 0 0 0 0 2600 0 375 0 500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5000 0 90000 0 0 0 0 0 0 4500 0 0 0 0 0 0 0 0 0 40000 1800 0 60000 0 0 0 0 0 0 0 375 0 0 0 0 0 100000 0 0 0 0 0 0 5000 0 0 0 500 0 0 0 0 0 50000 22000 0 30000 0 0 0 0 0 1800 0 600 0 200 0 2000 0 0 500 0 0 0 0 0 0 0 500 0 500 0 0 0 1000 0 30000 30000 0 300000 3000 0 0 0 0 0 0 0 0 1500 0 0 0 20000 0 0 0 0 0 0 500 0 200 0 0 0 0 0 0 0 end
Comment