On Wed, 23 Dec 2020, Artur Bala wrote:
Oh, that’s good!!! Probably not very suggestive but pretty fair
though :)
This one's a bit more sophisticated. Perhaps we could add this to the
"extra" package?
<hansl>
set verbose off
function void topbot(series x, scalar n[5])
genr index
catch markers --to-array=mrk
has_markers = !$error
smpl --no-missing
matrix tmp = {index, x}
r = rows(tmp)
tmp = msortby(tmp, 2)[,1]
selbot = tmp[1:n]
seltop = mreverse(tmp[r-n+1:r])
smpl full
printf "\nTOP BOTTOM\n"
printf "--------------------------------------------\n"
loop i = 1 .. n
kt = seltop[i]
kb = selbot[i]
if has_markers
printf "%10s: %10.3g", mrk[kt], x[kt]
printf "%10s: %10.3g\n", mrk[kb], x[kb]
else
printf "%10d: %10.3g", kt, x[kt]
printf "%10d: %10.3g\n", kb, x[kb]
endif
endloop
print ""
end function
# test without markers
open data4-1.gdt --quiet
topbot(price)
price[3] = NA # with missing values
topbot(price)
# test with markers
open greene9_1.gdt --quiet
topbot(labor,6)
labor[7] = NA # with missing values
topbot(labor,6)
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------