Tips for working with Tables

For tips, questions and general information about writing Add-ins, how to package them, and how to submit them to EViews for publication.

Moderators: EViews Gareth, EViews Moderator

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Tips for working with Tables

Postby EViews Gareth » Wed Apr 14, 2010 3:25 pm

Most output in EViews is in the form of an Table object, either as a stand alone object or, more frequently, as a table being shown inside another object (Equation estimation results, for example). However working with tables inside an EViews program can be...quirky. So here's some tips I have on working with them.

Table sizing
The number one weird thing about table objects is that they don't really have a size. You can create a table with 4 rows and 3 columns, and then tell EViews to put something into the 100th row, and EViews will quite happily do it, simply resizing the table on-the-fly to add the 96 extra rows. Even more weird, not only will it add 96 extra rows, but sometimes it will add a few more as padding.

Although this behaviour can be very handy - you don't have to worry about sizing the table upon creation, you can just make it any size and then fill in the cells as you go, it also has a number of drawbacks that you have to work around.

The first is that there is no way to find out how many rows/columns a table currently has. Thus if you want to add something to the end of a table, but don't know where the end is, it can be impossible to do. Thus you have to keep track of exactly how big your table is at all times.

A second, even bigger drawback, is that although a table object will resize itself when you tell it to enter data into a cell that isn't currently in the table, it will not resize itself when you adjust some of the formats of cells. For example, say you have the following code:

Code: Select all

table(3,3) mytab
mytab.setwidth(5) 20
mytab(1,5) = "My Table Header"

You might think that this would set the width of the 5th column to be 20, and then enter the text "My Table Header" into the top of the 5th column However since the table was created with only 3 columns, the setwidth command is ignored.

This is even more of a problem when you declare a table with no size at all, which is frequently the case:

Code: Select all

table mytab
mytab.setwidth(5) 20
mytab(1,5) = "My Table Header"

This code will behave exactly the same way as the above code - i.e. the setwidth command will be ignored, since a default table does not have 5 columns.

However the following code:

Code: Select all

table mytab
mytab(1,5) = "My Table Header"
mytab.setwidth(5) 20

will work, since the table has automatically added a 5th column before the setwidth command is used.

This means that you either have to create your table to be exactly the correct size, or you have to apply all of your formatting at the end of the table creation code.

There are undoubtedly even more quirks that the auto-resizing of tables can cause, so be on the look out!


Use Row/Column counters
I usually fill my tables in row by row, starting at the top. When I do this I use a program variable (usually called !row or !rowcounter) to keep track of which row I am on in the table. This means that rather than having code that looks like this:

Code: Select all

table mytab
mytab(1,1) = "This is my table header"
mytab(2,1) = "This is some time information"
mytab(3,1) = "This is some estimation information"
mytab(4,1) = "This is some forecast information"


I have code that looks like this:

Code: Select all

table mytab
!row=1
mytab(!row,1) = "This is my table header"
!row = !row + 1
mytab(!row,1) = "This is some time information"
!row = !row + 1
mytab(!row,1) = "This is some estimation information"
!row = !row + 1
mytab(!row,1) = "This is some forecast information"
!row = !row + 1


Clearly this way is a lot more cumbersome. However it has distinct advantages. The first is that I always know how many rows are in my table (!row). Secondly it means that if I decide to remove a row, or change position of a row, all I have to do is remove that line from the program, without changing any of the other lines. For example in the first code segment above, if I wanted to remove the "This is some time information" line, I would then have to change the third and fourth rows so that they now say:

Code: Select all

mytab(2,1) = "This is some estimation information"
mytab(3,1) = "This is some forecast information"


whereas all I have to do in the second segment is remove the line, none of the other lines need be changed at all.

Obviously, if you have 40 or so rows in your program this is a huge difference.

Further, if you want to copy and paste some table code from one Add-in program to another, if both programs are using the !row counter method, you can just copy and paste without having to worry about the size different.

Time/Date information
Many EViews output tables show the time/date that the procedure was performed. This can be added easily to your table with the following:

Code: Select all

%datestring = "Date: " + @datestr(@now,"MM/DD/YY") + "   Time: " + @datestr(@now,"HH:MI")
mytab(!row,1) = %datestring


Cell arithmetic
One more issue is that a lot of the table commands that take in cells will not let you perform arithmetic inside the command. i.e.:

Code: Select all

mytab.setfont(!row + 1, 3) +b

will error. You'll have to do the arithmetic outside the command:

Code: Select all

!temprow = !row + 1
mytab.setfont(!temprow,3) +b


This doesn't apply to direct cell assignment though - You can do the following:

Code: Select all

mytab(!row + 1, 3) = "hello"
Follow us on Twitter @IHSEViews

Armine
Posts: 7
Joined: Fri Jun 07, 2013 1:05 am

Re: Tips for working with Tables

Postby Armine » Thu Jun 20, 2013 5:25 am

Thanks it was very helpful, just one additional question to be sure, is there any limitation the number of rows in the table ?

Thanks, Armine

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: Tips for working with Tables

Postby EViews Gareth » Thu Jun 20, 2013 8:20 am

There probably is, but I'm not sure what it is. I just created a table with 10,000,000 rows, and it seemed to work ok.
Follow us on Twitter @IHSEViews

alexyflemming
Posts: 8
Joined: Wed Jan 23, 2013 8:22 am

Re: Tips for working with Tables

Postby alexyflemming » Thu Sep 19, 2013 4:13 am

Is there a way to define a series by making the series values a table values?
(I need this, because I could not graph the table data in a certain table. I have to define a series from this table)

That is to say,
Assume,

' Create a table that holds the values of delay multipliers of a ARDL(p,q) model
table(6,2) Tablebetas

Assume we loaded Tablebetas properly: For example:
Tablebetas(1,1)="Time Period Delay"
Tablebetas(1,2)= "Multiplier"

' Create an empty eq
equation esitlik
esitlik.ls du c du(-1) g g(-1)

'Number of multiplier to be calculated (0.impact, 1.delay, ..., 7.delay)
!nomultiplier = 8

!b0 = esitlik.@coefs(3)
!b1 = esitlik.@coefs(4) + !b0 * esitlik.@coefs(2)
!b2 = !b1*esitlik.@coefs(2)
smpl @first+1 @last

Tablebetas(2,2)= !b0
Tablebetas(3,2)= !b1
Tablebetas(4,2)= !b2
for !i=1 to !nomultiplier
esitlik.ls du c du(-1) g g(-1)
Tablebetas(!i+1,1)= !i-1
if !i>2 then
!j = !i -1
!b{!i} = !b{!j}*esitlik.@coefs(2)
Tablebetas(!i+1,2)= !b{!j}
endif
next
show esitlik.ls du c du(-1) g g(-1)
Tablebetas.display

The first column of table is just numbers: Time Period Delay; 0;1;2;2;3;4;5;6;7
The second column of table is the delay multipliers. Hence, I need to define a series whose values will be the 2nd column of Tablebetas from which I will be able to draw the contents of Tablebetas.
Alexy Flemming

alexyflemming
Posts: 8
Joined: Wed Jan 23, 2013 8:22 am

Re: Tips for working with Tables

Postby alexyflemming » Thu Sep 19, 2013 4:44 am

I found a very very dirty solution to my question above:

series Tablebetasseries

for !i=2 to !carpansayisi
Tablebetasseries(!i) = Tablebetas(!i,2)
Next

' Click Run. In the workfile environment, double click to Tablebetasseries. Take projection of the sample to the non-null values of Tablebetasseries: Quick - Sample – Sample Range Pairs: 1985q3 1987q1. In the workfile environment, click Tablebetasseries. Quick - Graph - Series List: Tablebetasseries– OK– OK.

At least, until a nice handling is suggested, the above technique can finish the jobs of some.

Alexy Flemming

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: Tips for working with Tables

Postby EViews Gareth » Thu Sep 19, 2013 7:51 am

Yep, looping through the values of the table one at a time is the only way to do it.

Note that using a table to store the numbers means you're storing them as text - you'll lose some precision.
Follow us on Twitter @IHSEViews


Return to “Add-in Writing area”

Who is online

Users browsing this forum: No registered users and 5 guests