On Mon, Mar 13, 2023 at 7:33 AM Artur T. <ate...@posteo.de> wrote: > > Hi all, > > I obtain an error with the aggregate() function when calling a > user-defined function for aggregation. > > The following example works fine, if one groups the data by a single > variable but it fails with a second group-by variable: > > <hansl> > set verbose off > clear > open grunfeld -q > > function scalar quantile_range (series y) > /* Compute the interquartile range. */ > > scalar ret = quantile(y, 0.75) - quantile(y, 0.25) > print ret > > return ret > end function > > # Works > list groupby = firmname > list L = invest value > matrix agg = aggregate(L, groupby, quantile_range) > print agg > > # Fails > list groupby = firmname ticker # we add "ticker" > list L = invest value > matrix agg = aggregate(L, groupby, quantile_range) > print agg > </hansl>
The aggregator function has to be coded a bit more defensively. Of the 100 cases of (firmname, ticker) 90 are empty, so it has to be ready to handle absence of data, as in if $nobs == 0 || sum(ok(y)) == 0 return NA endif Allin _______________________________________________ Gretl-devel mailing list -- gretl-devel@gretlml.univpm.it To unsubscribe send an email to gretl-devel-le...@gretlml.univpm.it Website: https://gretlml.univpm.it/postorius/lists/gretl-devel.gretlml.univpm.it/