coefs factors by loop

For questions regarding programming in the EViews programming language.

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

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

coefs factors by loop

Postby ch2324 » Sat Feb 27, 2016 7:53 am

Hi everybody
this code extract coefs factors in the vectors but i get a constant value in the vectors 0.605271, I have a fault somewhere :roll:

Code: Select all

vector(12) v equation eq eq.ls y y(-1) y(-2) @expand(@month) for !i= 1 to 12 for !j=3 to 14 v(!i)=eq.@coef(!j) next next
any help!

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

Re: coefs factors by loop

Postby EViews Gareth » Sat Feb 27, 2016 9:33 am

I think you want:

Code: Select all

vector(12) v equation eq eq.ls y y(-1) y(-2) @expand(@month) for !i= 1 to 12 !j = !i+2 v(!i)=eq.@coef(!j) next

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: coefs factors by loop

Postby ch2324 » Sat Feb 27, 2016 12:27 pm

it work, thanks!.
i use this code but a get a constant value in the matrix:

Code: Select all

matrix(4,3) m equation eq eq.ls y y(-1) y(-2) @expand(@month) for !i=1 to 4 for !j=1 to 3 !k=m(!i,!j) m(!i,!j)=eq.@coef(!k) next next
i would just put the factors coefs by column in the matrix.
(*) there is a tini mistake in EV9 command Ref chap 11 p 259. v1 should be v.

Code: Select all

vector(3) v v1.fill 0.1, 0.2, 0.3

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: coefs factors by loop

Postby ch2324 » Sun Feb 28, 2016 4:33 am

by this code i get one value of factors in m(1,1) but all others values are constant

Code: Select all

matrix(4,3) m equation eq eq.ls y y(-1) y(-2) @expand(@month) for !i=1 to 4 for !j=1 to 3 for !k= 3 to 12 if !i>=1 and !j=1 and !k=!i+2 then m(!i,!j)=eq.@coef(!k) if !i>=1 and !j=2 and !k=!i+6 then m(!i,!j)=eq.@coef(!k) if !i>=1 and !j=3 and !k=!i+10 then m(!i,!j)=eq.@coef(!k) next next next endif endif endif
I would highly appreciate if any of you could help me!

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

Re: coefs factors by loop

Postby EViews Gareth » Mon Feb 29, 2016 9:20 am

It is really difficult to figure out what you're trying to do.

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: coefs factors by loop

Postby ch2324 » Mon Feb 29, 2016 9:55 am

1)i would just place the four coefs of factors "c(3), c(4), c(5), c(6)" in the first column, and "c(7), c(8), c(9), c(10)" in the second column, ...etc
2) can i combined three vector(3) in the matrix(3,3) by function?

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: coefs factors by loop

Postby ch2324 » Mon Feb 29, 2016 10:15 am

1-sorry, is another question :oops: ok!, how can combined vector to the matrix by function?
2-vector v1 = @vec(m1), extract column to the vector, but how can extract by row to the vector, i have used @rows but it not work.
3- it's solved but can i use if to simplify by "if"

Code: Select all

matrix(4,3) m equation eq eq.ls y y(-1) y(-2) @expand(@month) for !i=1 to 4 !j=1 !k=!i+2 m(!i,!j)=eq.@coef(!k) for !i=1 to 4 !j=2 !k=!i+6 m(!i,!j)=eq.@coef(!k) for !i=1 to 4 !j=3 !k=!i+10 m(!i,!j)=eq.@coef(!k) next next next

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

Re: coefs factors by loop

Postby EViews Gareth » Mon Feb 29, 2016 10:41 am


ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: coefs factors by loop

Postby ch2324 » Mon Feb 29, 2016 11:26 am

thanks!
can you help me to simplify the code by "if", it's just to understand the methodologie of the loop by if. :roll:

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

Re: coefs factors by loop

Postby EViews Gareth » Mon Feb 29, 2016 11:49 am

That code is nearly impossible to follow. What are you trying to do?

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

Re: coefs factors by loop

Postby EViews Gareth » Mon Feb 29, 2016 12:02 pm

If you're trying to create a 4,3 matrix that contains the monthly coefficients:

Code: Select all

vector monthlycoefs = @subextract(eq.@coefs, 3) 'extract the coefficients from the 3rd onwards into a vector matrix m = @unvec(monthlycoefs, 4) 'convert that vector into a matrix.

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: coefs factors by loop

Postby ch2324 » Mon Feb 29, 2016 1:18 pm

exactlly what that i need, i learned many things from you Mr Gareth many thanks!
(**) EViews 9 Command Ref, chap 11, pp 264-265
matrix xsub = x.@row(@fill(1, 3, 4))
extracts the first, third, and fourth rows of the matrix X into the matrix XSIB. XSIB should be xsub.

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: coefs factors by loop

Postby ch2324 » Sat Mar 05, 2016 11:40 am

(***)EViews 9 Command Ref, chap 11, p 264
vector a = x.@row(3)
extracts the third column of X into the vector a, "column should be row". :)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests