[Gretl-devel] Bugs, missing features and a suggestion
Riccardo (Jack) Lucchetti
r.lucchetti at univpm.it
Wed Sep 26 06:49:41 EDT 2007
On Wed, 26 Sep 2007, andreas.rosenblad at ltv.se wrote:
> Well, currently I have to do as follows:
>
> a = rows(A)
> smpl 1 a
> series Anew = A
> series Bnew = B
> xtab Anew Bnew
> delete Anew bnew
> smpl --full
>
> Thus, I have to use 7 commands. Instead I would like to use just one
> command:
>
> xtab A B
>
> It would be much easier and efficient, having to write less code. So I
> would really appreciate it.
I see your point; I may even concede that adding this feature to the xtab
command could be worth the trouble. However, the reason why user-level
function are present in gretl is exactly to handle cases like yours. I
don't see why it should be a problem to wrap your sequence of commands
into a function.
> For a matrix C = {3,2;2,3} gretl currently give the following output:
>
> ? C
> C (2 x 2)
>
> 3 2
> 2 3
>
> What I am asking for is following output
>
> ? xtab C
>
> [ 1][ 2] TOT.
>
> [ 1] 3 2 5
> [ 2] 2 3 5
>
> TOTAL 5 5 10
>
> I need this function mainly for producing nice outputs with column and row
> headings, and I thought this would be the easiest way to implement it.
Let's separate the issues: in theory, you can get the numbers easily by
something like
D = ( C ~ sumr(C) ) | ( sumc(C) ~ sumc(sumr(C)) )
but this seems not to work at present; it's a bug, and I thank you for
unearthing this. However, the following workaround does work:
D = C ~ sumr(C)
e = sumc(C) ~ sumc(sumr(C))
D = D | e
As for the labels, I think there's no easy way out: the information
contained in the matrix tells you nothing on the labels that you want
printed, so your next point may be interesting.
> A better solution, that better suits my needs, but maybe is harder to
> implement, is to create a new "printtable" command that attaches column and
> row names to a matrix (something like the dimnames argument in the matrix
> command in R) as well as row and column headings.
>
> Ideally, a command "printtable" would produce something like:
>
> A = {3, 2, 5; 2, 3, 5; 5, 5, 10}
>
> printtable A rownames={"row 1", "row2", "Total"} columnnames={"col 1", "col
> 2", "Total"} \
> columnheading="Variable 1" rowheading="Variable 2"
>
> And then with this input give the following output:
>
> Variable 1
> col 1 col 2 Total
> row 1 3 2 5
> Variable 2 row 2 2 3 5
> Total 5 5 10
>
> Would this be possible to implement in gretl?
As things stand now, this would be a bit hard since gretl has no concept
of an array that you can fill in with strings (to put it simply). If this
extension was implemented (not a priority IMO) it would not be difficult
to write a user-level function like
printtable(matrix A, strarray rownames, strarray colnames, string chead, \
string rhead)
by using the already amazingly flexible printf command.
>>> 3. After calculating a cross classification table from View > Cross
>>> Tabulation in the GUI, one gets the possibility to save the output
> table as
>>> a matrix. This feature should be available also from the command line
>>> interface.
>>
>> This is exactly what the mxtab function is for. Am I missing something?
>
>
> I'm sorry, I couldn't find anytning about that function in the Gretl
> Command Reference, the Gretl User's Guide or the help files.
Oof, you're right, sorry. It's not in the manual. I'll update it as soon
as I can.
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti at univpm.it
http://www.econ.univpm.it/lucchetti
More information about the Gretl-devel
mailing list