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>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------