Hi there,
I have a function (WIP) to produce input for a boxplot side-by-side comparison of cross-section statistics of two samples (see below). The list seems to pass the names of the series, but does not work. If I remove the function body, everything
works.
<hansl>
function matrix MatOrderDist (list ls, list lsB[null])
#A function to create data for order stats boxplots (cross-section)
scalar two = 0 #no
scalar entries = nelem(ls)
if exists(lsB)
if nelem(lsB)==entries
two = 1 #yes
endif
endif
strings coln = array(6)
coln[1] = "min"
coln[2] = "lq"
coln[3] = "med"
coln[4] = "uq"
coln[5] = "max"
coln[6] = "avg"
if two
matrix to_plot = zeros(entries,12)
strings colnf = array(12)
loop i=1..12
colnf[i]=coln[i]
colnf[i+1]=coln[i]
i+=1
endloop
else
matrix to_plot = zeros(entries,6)
strings colnf = array(6)
loop i=1..6
colnf[i]=coln[i]
endloop
endif
colnames(to_plot,colnf)
scalar r = 0
scalar offset = 0
if two
offset = 1
endif
loop foreach item ls -q
r+=1
to_plot[r,1] = min($item)
to_plot[r+offset*r,2] = quantile($item,.25)
to_plot[r+offset*r,3] = quantile($item,.5)
to_plot[r+offset*r,4] = quantile($item,.75)
to_plot[r+offset*r,5] = max($item)
to_plot[r+offset*r,6] = mean($item)
endloop
if two
loop foreach item lsB -q
r+=1
to_plot[r+offset*(r-1),1] = min($item)
to_plot[r+offset*(r-1),2] = quantile($item,.25)
to_plot[r+offset*(r-1),3] = quantile($item,.5)
to_plot[r+offset*(r-1),4] = quantile($item,.75)
to_plot[r+offset*(r-1),5] = max($item)
to_plot[r+offset*(r-1),6] = mean($item)
endloop
endif
#boxplot --matrix=to_plot --output=display {set title "Cross-Section Distribution of Summary Statistics (Original Programme)"; }
return to_plot
end function
</hansl>