How to build a matrix to store coefficients?

For questions regarding programming in the EViews programming language.

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

nsea411
Posts: 9
Joined: Wed Jan 20, 2021 9:02 am

How to build a matrix to store coefficients?

Postby nsea411 » Mon Jan 25, 2021 5:05 am

Dear friends,

I have regressed 228 regressions now, and I want to build a matrix to store the coefficients and here is my code(unsuccessful to build the matrix) .

Code: Select all

wfopen C:\Users\dell\Desktop\data.xls

for !i= 1 to 12  'month
for !j=2001 to 2019   'year

smpl {!j}m{!i} {!j}m{!i}

genr a{!j}{!i} =ri
genr b{!j}{!i} =roil
genr c{!j}{!i} =rm

matrix(3,{!j}{!i}) coefs

equation eq{!j}{!i}.ls a{!j}{!i} c b{!j}{!i} c{!j}{!i}

colplace(coefs, eq{!j}{!i}.@coefs,{!j}{!i})
next
next


I try to build a matrix according to http://forums.eviews.com/viewtopic.php?t=1638#p5508(An introduction to EViews programming by Gareth), but because I select subsamples according to date(yyyy-mm) which contains 2 for loops, I don't know how to build a valid matrix and store the coefficients correctly.

If anyone can give me a hand, I will be grateful!
Thank for your kind in advance!

EViews Matt
EViews Developer
Posts: 563
Joined: Thu Apr 25, 2013 7:48 pm

Re: How to build a matrix to store coefficients?

Postby EViews Matt » Mon Jan 25, 2021 2:52 pm

Hello,

There's really only two changes needed fix your existing code. First, you don't need to be creating the coefs matrix on every iteration of the loops, that should be done just once before the loops. The number of columns in the matrix can be directly calculated, i.e. 12 * 19 = 228. Second, when using the colplace function, you need to provide a column number as the third argument. The {!j}{!i} expression is going to produce numbers between 20011 and 201912, which clearly isn't appropriate for a matrix that contains only 228 columns. Basically, you need to devise a formula involving !j and !i that will produce an appropriate number between 1 and 228, such as "(!i - 1) * 19 + !j - 2000".

nsea411
Posts: 9
Joined: Wed Jan 20, 2021 9:02 am

Re: How to build a matrix to store coefficients?

Postby nsea411 » Mon Jan 25, 2021 7:37 pm

EViews Matt wrote:Hello,

There's really only two changes needed fix your existing code. First, you don't need to be creating the coefs matrix on every iteration of the loops, that should be done just once before the loops. The number of columns in the matrix can be directly calculated, i.e. 12 * 19 = 228. Second, when using the colplace function, you need to provide a column number as the third argument. The {!j}{!i} expression is going to produce numbers between 20011 and 201912, which clearly isn't appropriate for a matrix that contains only 228 columns. Basically, you need to devise a formula involving !j and !i that will produce an appropriate number between 1 and 228, such as "(!i - 1) * 19 + !j - 2000".


Thank you very much! I have tried your way and done successfully. :lol:


Return to “Programming”

Who is online

Users browsing this forum: Baidu [Spider] and 20 guests