EDIT: I use gcollapse (ssc inst gtools, replace), but regular collapse works fine.
When I sort a matrix like this
it robs me of my precious row and column labels.
Why might this be?
When I sort a matrix like this
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input long code float(premse postmse ratio rmspe_rank p)
11 .05515488 2.771367 50.247 1 .16666667
12 .14310792 .2025988 1.4157065 6 1
26 .012931863 .5920703 45.78384 3 .5
27 .02456784 1.1890676 48.39935 2 .3333333
35 .029555114 .3298432 11.160275 5 .8333333
51 .0257518 .880294 34.183784 4 .6666667
end
label values code code
label def code 11 "Rondônia", modify
label def code 12 "Acre", modify
label def code 26 "Pernambuco", modify
label def code 27 "Alagoas", modify
label def code 35 "São Paulo", modify
label def code 51 "Mato Grosso", modify
gcollapse (firstnm) premse postmse ratio rmspe_rank p, by(code)
decode code, g(panel)
mkmat premse postmse ratio rmspe_rank p, rownames(panel) mat(errmat)
matname errmat "Pre-MSE" "Post-MSE" "Ratio" "Rank" "p", columns(1..5) explicit
mata : st_matrix("errmat", sort(st_matrix("errmat"), 4))
mat l errmat
Code:
. mat l errmat
errmat[6,5]
Pre-MSE Post-MSE Ratio Rank p
Rondônia .05515488 2.7713671 50.247002 1 .16666667
Acre .14310792 .2025988 1.4157065 6 1
Pernambuco .01293186 .59207028 45.78384 3 .5
Alagoas .02456784 1.1890676 48.399349 2 .33333331
São_Paulo .02955511 .32984319 11.160275 5 .83333331
Mato_Grosso .0257518 .88029402 34.183784 4 .66666669
. mata : st_matrix("errmat", sort(st_matrix("errmat"), 4))
.
.
. mat l errmat
errmat[6,5]
c1 c2 c3 c4 c5
r1 .05515488 2.7713671 50.247002 1 .16666667
r2 .02456784 1.1890676 48.399349 2 .33333331
r3 .01293186 .59207028 45.78384 3 .5
r4 .0257518 .88029402 34.183784 4 .66666669
r5 .02955511 .32984319 11.160275 5 .83333331
r6 .14310792 .2025988 1.4157065 6 1

Comment