Coefficients count

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

cazeek
Posts: 5
Joined: Sat Feb 23, 2019 1:00 pm

Coefficients count

Hello,

I'm creating a simple program that will export the estimated coefficients of a linear regression to a table (which I'll then use w/ the COM add-in later on). The program will loop through each equation of the workfile and save each equations' coefficients to a vector or table. This is the first few lines:

Code: Select all

%eqlist = @wlookup("*", "equation")

for !i=1 to @wcount(%eqlist)
%reg = @word(%eqlist, !i)

The next step would be

Code: Select all

for !j= 1 to ??
where ?? needs to be some way of counting the coefficients in {%eqlist} so I can loop through each and store to the vector. How can I do this (and totally open to another way to go about this if recommended?

Thanks!

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

Re: Coefficients count

http://www.eviews.com/help/helpintro.ht ... on.html%23

Scroll to the data members.

The precise answer to your question is the @ncoefs member, but the @coefs member will probably be better for you.

cazeek
Posts: 5
Joined: Sat Feb 23, 2019 1:00 pm

Re: Coefficients count

Thanks so much for the speedy reply- both are perfect!

Two more quick question, and apologies for the first, as I'm sure this is right in front of me on that page, but can't seem to find it.

1) How can I get the name of the regressors from the equation? I realized I'm going to want those as well in a 2 column table.
2) I'm trying to name the table as "tbl_" and the equation name (e.g. tbl_reg1, tbl reg2). My syntax is off, as I'm getting the error TBL"REG_GCE_R" is an illegal or reserved name, so I believe my syntax is passing the quotes through b/c %reg is a string.

Code: Select all

%eqlist = @wlookup("*", "equation")

for !i=1 to @wcount(%eqlist)
%reg = @word(%eqlist, !i)
table({%reg}.@ncoefs,2) tbl%reg *********
for !j=1 to {%reg}.@ncoefs
tbl_%reg(!j,1) = {%reg}.?X?  *******
tbl_%reg(!j,2) = {%reg}.@coef(!j)
next
next

Thanks again Gareth- very much appreciate the Saturday afternoon replies!

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

Re: Coefficients count

Look at @spec or @varlist on that page.

Put {} around %reg

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

Re: Coefficients count

Also, you might want to download the EqTabs add-in and look at the source code - it does very similar stuff to what you’re doing

cazeek
Posts: 5
Joined: Sat Feb 23, 2019 1:00 pm

Re: Coefficients count

Awesome- thanks so much again. That add-in helped tie the last piece together as well. For those that stumble upon this, here is my final code if interested:

Code: Select all

%eqlist = @wlookup("*", "equation")

for !i=1 to @wcount(%eqlist)
%reg = @word(%eqlist, !i)
table({%reg}.@ncoefs,2) tbl_{%reg}
for !j=1 to {%reg}.@ncoefs
tbl_{%reg}(!j,1) = @wmid({%reg}.@spec(!j),!j+1,1)
tbl_{%reg}(!j,2) = {%reg}.@coef(!j)
next
next