On Sun, 26 Oct 2014, Sven Schreiber wrote:
Am 26.10.2014 um 19:15 schrieb Pindar:
> Am 26.10.2014 14:59, schrieb Sven Schreiber:
>> Am 26.10.2014 um 14:22 schrieb Pindar:
>>> Hi there,
>>>
>>> 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]
>>>
>> Most importantly, I get a gretl crash when I insert the line
>> 'smpl ok(test) --restrict'
>> after the line where 'test' is created, so that looks like there might
>> be a deeper issue here. (However, this is with an older snapshot from
>> August on Windows, haven't tested yet whether it also occurs in newer
>> versions.)
>
> Hi Sven,
>
> at least with gretl 1.10.0cvs MS Windows (x86 64) build date 2014-10-18
> there is no such crash.
I still get the crash with the latest snapshot on Windows 8 (32bit I
think). Recipe as described above with the 'smpl ok(test) --restrict' line.
Confirmed here. I'm working on it. This seems to be a "perfect
storm" case -- some combination of boolean sample restriction, panel
data, user-defined function and use of aggregate() -- and I haven't
untangled it yet.
Allin Cottrell