On Tue, 11 Mar 2008, Stefano Balietti wrote:
I tried to access the single values of the $coeff array directly with
the
command
a = $coeff[x,1]
that is a usage of the $coeff array not mentioned in the command
reference, but anyway it is supposed to return a scalar. On the
contrary it returns a matrix 1x1.
It now returns a scalar unless you force the issue by saying
matrix a = $coeff[x,1]
i could specify the new variable as scalar
scalar a = $coeff[x,1]
but here another inconvenient raises. If I try to print the variable a
without explicitly using the print command, after a few runnig of the same
script gretl crashes...
Thanks for the example. Fixed in CVS.
By the way it could be nice to access the coefficients in the
array with a command like $coeff( number), useful if you don't
know the name of the variables.
The documentation seems to have slipped a little on this point;
I'll try to fix that soon. But here's the deal:
$coeff(foo) : with round parentheses we require the name of a
parameter.
$coeff[k] : with square brackets we select a coefficient by number
(position in the array)
If you want to get the coefficient of a certain variable whose ID
number in the dataset you know, but whose name you don't know
(and whose position in the array you don't know -- though that
seems a bit weird):
string vname = varname(ID)
scalar b = $coeff(@vname)
In (very) current CVS you could omit the '@':
scalar b = $coeff(vname)
It would be preferable if you could do
scalar b = $coeff(varname(ID))
but strings are not yet sufficiently tightly integrated in
genr.
Allin.