Store coefficients of several AR equations

For questions regarding programming in the EViews programming language.

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

epeter
Posts: 16
Joined: Wed May 28, 2014 1:59 am

Store coefficients of several AR equations

Postby epeter » Wed May 28, 2014 2:25 am

Dear all,

I apologize in advance for my basic english AND my poor knowledge of eviews.

I have 388 series, and for each serie i run 6 equations ( AR(1), AR(2), AR(3), AR(4), AR(5), AR(6) ).

Code: Select all

group g * 'put every series in the workfile into a group g.drop resid for !i=1 to g.@count 'loop through every series in the first group %name = g.@seriesname(!i) 'grab the current series name for !p = 1 to 6 if !p = 1 then %ar = "ar(1)" else %ar = %ar + "ar(" + @str(!p) + ")" endif equation eq{!i}_ar{!p}.ls {%name} c {%ar}
I'm looking for a code to store the coefficients (constant and AR coefficients) of each equation i've run. I've tried by using the "colplace" command but i experienced matrix size mismatch problems.

Thanks in advance for your help!

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

Re: Store coefficients of several AR equations

Postby EViews Gareth » Wed May 28, 2014 4:21 am

You have 388 series and 7 coefficients per equation. Thus you need to make a matrix of size 7x388. Then you should be able to use colplace.

epeter
Posts: 16
Joined: Wed May 28, 2014 1:59 am

Re: Store coefficients of several AR equations

Postby epeter » Wed May 28, 2014 5:40 am

Thank you very much Gareth,

unfortunately i still have the same error message "matrix size mismatch in "COLPLACE(coefficients, eq{!i}_ar{!p}.@coefs,!i)".
Is this due to the fact that the number of coefficients change for different equations?
for example, in AR(1) i have the constant and 1 coefficient; in AR(2) i have the constant and 2 coefficients ...

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

Re: Store coefficients of several AR equations

Postby EViews Gareth » Wed May 28, 2014 5:55 am

Ah, yes, I am an idiot and didn't notice that you were varying the number of coefficients. Yes, that is the error.

Cycle through the coefficients one at a time:

Code: Select all

for !j=1 to !p mycoefs(!j,!i) = eq.@coef(!j) next
or something similar.

epeter
Posts: 16
Joined: Wed May 28, 2014 1:59 am

Re: Store coefficients of several AR equations

Postby epeter » Wed May 28, 2014 6:52 am

I followed your advice, but unfortunately i get a table with only the 6 coefficients of each AR(6) equation of each serie. What i'm looking for is to have a table (or matrix), with, for each serie (thus, 388 columns), not only the coefficients of the equation AR(6), but also those of an AR(5), AR(4) and so on...

I really appreciate your help Gareth!

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

Re: Store coefficients of several AR equations

Postby EViews Gareth » Wed May 28, 2014 7:02 am

Ah, ok, you want multiple equations for each variable. Your current code doesn't really do that. Try this:

Code: Select all

create u 100 !n=388 for !i=1 to !n series x!i=nrnd next !maxar = 6 group g * 'put every series in the workfile into a group g.drop resid for !i=1 to !maxar matrix(!i+1, !n) coefs_ar!i next for !i=1 to g.@count 'loop through every series in the first group %name = g.@seriesname(!i) 'grab the current series name for !p=1 to !maxar equation eq_{%name}_ar!p.ls {%name} c ar(1 to !p) colplace(coefs_ar!p, eq_{%name}_ar!p.@coefs, !i) next next
You can remove the first bit, where I'm just generating some random data.

epeter
Posts: 16
Joined: Wed May 28, 2014 1:59 am

Re: Store coefficients of several AR equations

Postby epeter » Thu May 29, 2014 1:58 am

Yess!! Thank you so much Gareth! It works perfectly!! :))


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests