On Tue, 19 Feb 2013, Riccardo (Jack) Lucchetti wrote:
On Tue, 19 Feb 2013, ahmadou dicko wrote:
>> This functionality is not built-in (except in relation to the
>> "summary" command, using the --by option). However it's
>> possible to write a function to do this sort of thing. The
>> following is not very general but should give you the idea:
>>
>> <hansl>
>> function matrix aggregate (series x, series y, string funname)
>> matrix m = values(y) ~ 0
>> loop i=1..rows(m) --quiet
>> smpl y == m[i,1] --restrict --replace
>> m[i,2] = @funname(x)
>> printf "@funname(x) for y=%g: %g\n", m[i,1], m[i,2]
>> endloop
>> colnames(m, "y f(x)")
>> return m
>> end function
>>
>> open credscore.gdt
>> m = aggregate(Income, Acc, "mean")
>> print m
>> m = aggregate(Income, Acc, "sd")
>> print m
>> </hansl>
Mmmm. I like it. This as a native function would be very nice to have. Plus,
this is one of those cases in which C would be much much faster than hansl.
Agreed. In tonight's CVS we have a native function, aggregate(), on
the pattern shown above, which supports the methods sum, mean, sd,
var, sst, skewness, kurtosis, min, max, median and gini. It'll be in
the snapshots tomorrow.
Allin Cottrell