Am 09.01.2018 um 14:59 schrieb Schaff, Frederik:
Sorry for so many questions ;) I still find new ones.
No problem at all.
a)Is there a way to access rownames similar to ‘colname(matrix M,
scalar
column)’? If yes, do rownames default to the index, if not explicitly
provided? How das print matrix access the rownames?
Hm, good question. I don't know why there is no rowname analogue to
colname(). I was going to say "use the transpose", but this doesn't work
for me, either. There was a question on the mailing list by Henrique
Andrade in 2016 about the row names being lost after applying
mreverse(). So applying transp() has the same effect apparently.
b)I am trying to find a solution to get the observation number of a
specific entry of a series in a subsampling (i.e., the integer with
which I could access this entry in the full sample), in order to
synchronise it with a matrix OBSDATE I have in a bundle that is passed
to this function and holds string labels for each element in the full
sample.
I can check via $nobs == nrows(OBSDATE) if there is a subsampling (which
will not always work..), but I do not know, how I can then treat with it
(in both cases, time-series data and cross-section data). If I use “obs”
to generate a new series, than it does not relate to the global
identifiers but creates a new, small series of consecutive integers (as
is stated within the help). At the same time, the series within the
bundle is not synchronised with the global series’. Is there a way to
deal with this? Or is the only option to print an error message and
demand that the bundle is reinitialised accordingly with a series
“obsdate=obs” from outside any function definition? Isn’t there a
(hidden) accessor for a series entries’ real (i.e. in full sample)
obsnumber/date?
I'm not sure I understand the question. The observation numbers/indices
in the dataset do not depend on subsampling. See for example:
<hansl>
open hendry_jae.gdt # annual data from 1873 to 1991
eval obslabel(1) # gives 1873
smpl 1900 1991
eval obslabel(1) # still gives 1873
</hansl>
perhaps $sample is an option? (Although I do not know how… ) and
basically $t1 and $t2 work for the first and last element in the current
(sub)sample, but the values in between are not provided?
Do you want to check for subsampling? You could check whether $t1==1 and
$t2==$tmax.
Caveat: For panel data --especially unbalanced-- it could be more
tricky. Perhaps something like this:
series check = 1
smpl full
checksum = sum(missing(check))
smpl --no-missing check # restore to the initial sample, if different
The if checksum is positive, the initial sample was a subsample. (Some
setobs magic might be needed afterwards to really reimpose the panel
structure.)
c)Misc. feedback :
a.obs and obsnum are not highlighted in the editor (but the question
mark works nonetheless)
True for obs, but obsnum() works here.
BTW I notice that 'obs()' (with parentheses) doesn't work -- I think
this should be mentioned in the function ref.
b.Instead of “varname()” one needs to use “argname()” to get the name
of
a series (even when passed by pointer). This could be noted in the gretl
help
You mean inside a function, and you want a cross-reference from the help
for varname() to the help for argname()?
c.neither argname nor varname work on elements contained within a
bundle. It does also not help to make an new series from the series
within the bundle (btw., pointer arithmetic is not allowed at all in
this case). It would be nice if this would work.
If I understand correctly, this is what I meant earlier when I said "if
you use bundles, you need good documentation for what they contain".
I don't think it's possible to get what you want. For example a bundle
can contain many series. Do you want to retrieve all the names in there?
If yes, what are you going to do about it without having some meta
knowledge about what each of them represents?
d.A recursive “exists” for bundles would be nice. I.e. if I ask
“exists(a.b.x)” it is checked if x exists, but if “b” already is
missing, an error is produced. Perhaps a exists(a.b.x) --recursive
option? Alternatively, if conditions would be checked one at a time,
this would also help. For example ‘if exists(a.b) && exists(a.b.x)’ does
not work if a.b does not exist
Are you talking about nested bundles here? Are you aware of the
inbundle() function? (Which isn't recursive AFAIK, though.)
But indeed it sounds as if it might be useful to turn the not yet
possible 'exists(b["hey"])' into an alias for something like:
if exists(b)
if inbundle(b, "hey")
return <type code for b.hey>
else
return 0
endif
else
return <new code? NA?>
endif
d)Misc. questions:
a.When I attach, within a function, a genr element (like series) that
was passed by pointer to the function, to a bundle, it is in fact copied
(hansl-primer p.20). Is there a way to instead add pointers to the
bundle? Perhaps by means of using the array type?
No I don't think so. What you could do is store your own reference to
the series, so for example save the argname() as a string, and then work
with that. Apart from that a gretl list is basically just a set of
references to existing series, and recently it was made possible to add
a list to a bundle, so perhaps that's your solution.
Or also the integer ID via varnum(), but that may change so I tend to
avoid it. (Strictly speaking the string name may also change, but only
through explicit action AFAIK.)
good luck,
sven