Thanks for all replies. It seems there are several alternative ways of doing this. Here is the final look of the option I took to compute a cross sectional mean and a cross sectional standard deviation functions:
<hansl>
function series my_cross_sectional_mean (list L)
set skip_missing off
matrix m = {L}
matrix result = {}
loop i=1..rows(m)
matrix mi = m[i,]
result |= meanr(selifc(mi, ok(mi)))
# and analogous with sdc(selifc(...)')'
endloop
series cross_sectional_mean = result
return cross_sectional_mean
end function
function series my_cross_sectional_stdev (list L)
set skip_missing off
matrix m = {L}
matrix result = {}
loop i=1..rows(m)
matrix mi = m[i,]
result |= sdc(selifc(mi, ok(mi))',sum(ok(mi))-1)'
# I'm using sum(ok(mi))-1 as degrees of freedom, to correct sdc for the sample standard deviation
endloop
series cross_sectional_stdev = result
return cross_sectional_stdev
end function
# load example data
open data4-10
list L = ENROLL CATHOL INCOME
INCOME[10] = NA
series mL = my_cross_sectional_mean(L)
series sL = my_cross_sectional_stdev(L)
print L mL sL -o
</hansl>
I used a correction for degrees of freedom in the sdc formula. The above code works perfectly!
Filipe