On Sun, 26 Oct 2014, Pindar wrote:
I'm interested in calculating a geometric mean inside the
aggregate
function in a panel dataset. While my UDF works in plain script the
results when using as aggregation function are wrong. Could you please
help me with this issue, here is the hansl script:
function scalar fn_geomean(series X)
catch scalar Y = prodc({X})^(1/nobs(X))
if $error<>0
Y=NAN
endif
return Y
end function
open abdata.gdt
series test = abs(n)
matrix testmean = aggregate(test, const, mean)
eval mean(test)~ testmean[, 3]
matrix testgeomean = aggregate(test, const, fn_geomean)
eval fn_geomean(test) ~ testgeomean[, 3]
Thanks for the report. I've now found the bug and it's fixed in CVS and
snapshots. Your script should now produce the expected results, with or
without the addition that Sven tried, namely inserting a sample
restriction to discard missing values,
smpl ok(test) --restrict
after generating the "test" series.
Allin Cottrell