Hi there,

I noticed that the summary command does show the within and between variation for a series but not for lists.
Hence, I wanted to calculate the variation components with a UDF.

On page 33 of this presentation http://fmwww.bc.edu/repec/msug2010/mex10sug_trivedi.pdf
the stata output for the series mdu of the data set 'mus18data.dta' (http://fmwww.bc.edu/ec-p/data/mus/) is shown.
The only difference to the gretl output is the calculated within variation:
STATA  2.5759
gretl    3.0627

When trying to calculate it myself I came up with totally different outcomes.
How is it correct?  Is there 'a' correct method?

Cheers
Leon

<hansl>
summary mdu
series x_bar_i= pmean(mdu)
series x_bar = mean(mdu)
## between variation
eval sd(pmean(mdu)) # OK
eval sqrt(sum(((x_bar_i-x_bar)^2))/5908/5) # OK, Baltagi (2003) p.76f
## within variation
eval mean(psd(mdu)) # wrong
eval sqrt(sum((mdu-x_bar_i)^2)/5908/5) # wrong,  Baltagi (2003) p.76
<hansl>