Am 08.09.19 um 10:59 schrieb Riccardo (Jack) Lucchetti:
On Sun, 8 Sep 2019, Artur Tarassow wrote:
> Hi all,
>
> for some function I need to check whether the passed series
> corresponds to the variable defining the cross-sectional dimension of
> a panel dataset.
[...]
> Do you some other ideas?
If the variable in question is guaranteed to be discrete, you could
use this:
<hansl>
function scalar is_crossdim_index_series(series x)
ret = isdiscrete(x)
if !ret
return ret
endif
matrix H = mxtab(x, $unit) .> 0
# check for 1-to-1 correspondence
chk = sumr(H) | sumc(H)'
ret = (maxc(chk) == 1) && (minc(chk) == 1)
return ret
end function
# example
open abdata.gdt --quiet
eval is_crossdim_index_series(YEAR)
discrete unit
eval is_crossdim_index_series(unit)
</hansl>
Nice solution, Jack. Works fine here. Maybe another candidate for
extra.gfn? Looks like a basic helper function to me.
Best,
Artur