Page 1 of 1

Coefficients count

Posted: Sat Feb 23, 2019 2:35 pm
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!

Re: Coefficients count

Posted: Sat Feb 23, 2019 2:44 pm
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.

Re: Coefficients count

Posted: Sat Feb 23, 2019 3:09 pm
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!

Re: Coefficients count

Posted: Sat Feb 23, 2019 3:15 pm
Look at @spec or @varlist on that page.

Put {} around %reg

Re: Coefficients count

Posted: Sat Feb 23, 2019 3:17 pm
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

Re: Coefficients count

Posted: Sat Feb 23, 2019 3:35 pm
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