Page 1 of 1

Obtaining coefficients only

Posted: Wed Mar 17, 2010 7:54 am
by Tadej
Hello.

Could someone please tell me what am I missing to obtain the coefficients only, from the regressions:

'create vector to store betas
vector(72) coef

'create empty equation to be used inside the loop
equation eq

''counter of how many equations we have run
!rowcounter=1

'run pairwise regressions between each y and relevant x
for !i=1 to 72
for !j=1 to 72
if !i<>!j then
equation eq{!i}.ls y{!i} c x{!i}
coefs(!rowcounter) = eq.@coef
!rowcounter = !rowcounter+1
endif
next
next

I get this error message: equation estimates are invalid or nonexistent in "COEFS(1)=EQ.@COEF"

Thank you for your help.

Best regards

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 8:12 am
by startz
You have a typo. "coef' versus "coefs"
Hello.

Could someone please tell me what am I missing to obtain the coefficients only, from the regressions:

vector(72) coef

coefs(!rowcounter) = eq.@coef

I get this error message: equation estimates are invalid or nonexistent in "COEFS(1)=EQ.@COEF"

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 8:23 am
by Tadej
Thank you startz for the reply. This though stil doesn't fix the problem. I am stil getting the same error message.

Maybe if you try it yourself:

'create a workfile
wfcreate d 2004 2010

'create 72 y series
for !i=1 to 72
series y{!i}=nrnd
next

'create 72 X series
for !i=1 to 72
series x{!i}=nrnd
next

'create vector to store betas
vector(72) coef

'create empty equation to be used inside the loop
equation eq

''counter of how many equations we have run
!rowcounter=1

'run pairwise regressions between each y and relevant x
for !i=1 to 72
for !j=1 to 72
if !i<>!j then
equation eq{!i}.ls y{!i} c x{!i}
coef(!rowcounter) = eq.@coef
!rowcounter = !rowcounter+1
endif
next
next

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 8:58 am
by startz
Try

Code: Select all

eq.@coefs(2)
if you want the second coefficient.

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 9:30 am
by Tadej
I still get the error message of: equation estimates are invalid or nonexistent in "COEFS(1)=EQ.@COEF". Something else must be missing in the program...Any idea?

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 9:40 am
by EViews Gareth

Code: Select all

equation eq{!i}.ls y{!i} c x{!i} coefs(!rowcounter) = eq.@coef
You're creating an equation called eq{!i}, but you're referencing an equation called eq.

You probably want to change your code to be:

Code: Select all

equation eq{!i}.ls y{!i} c x{!i} coefs(!rowcounter) = eq{!i}.@coef

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 9:58 am
by Tadej
Thank you Gareth.

Now I get the following error: non numeric argument in "COEFS(1) = EQ.1@COEF".

I really appreciate your help.

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 10:58 am
by EViews Gareth
You need Startz's fix for that:
@coefs(2)

Re: Obtaining coefficients only

Posted: Wed Mar 17, 2010 5:22 pm
by Tadej
Class guys, thanks a lot. Now I don't get an error message anymore. However, the vector beta still doesn't contain coefficients after I run the program.

Code: Select all

create vector to store betas vector(72) coefs 'counter of how many equations we have run !rowcounter=1 'run pairwise regressions between each series for !i=1 to 72 for !j=1 to 72 if !i<>!j then equation eq{!i}.ls y{!i} c x{!i} coefs(!rowcounter)=eq{!i}.@coefs(2) endif next next
I think the problem lies in rowcounter. Since if I set it to 72 (!rowcounter=72) I get the right coefficient saved in the coefs vector but only for the 72nd equation. It's the same if I specify:

Code: Select all

'counter of how many equations we have run for !i = 1 to 72 !rowcounter=!i next
What am I still doing wrong? I am feeling silly already since I am posting so many questions. I appologize for that but as you know this is the first time I write the programming language.

Re: Obtaining coefficients only

Posted: Thu Mar 18, 2010 8:01 am
by tchaithonov

Code: Select all

'counter of how many equations we have run for !i = 1 to 72 !rowcounter=!i next
What you are doing here is just changing !rowcounter within a loop and then do nothing afterwards. If you need move to the next element in the coef vector, you need to do this:

Code: Select all

create vector to store betas vector(72) coefs 'run pairwise regressions between each series for !i=1 to 72 !rowcounter = !i for !j=1 to 72 if !i<>!j then equation eq{!i}.ls y{!i} c x{!i} coefs(!rowcounter)=eq{!i}.@coefs(2) endif next next

Re: Obtaining coefficients only

Posted: Thu Mar 18, 2010 8:33 am
by Tadej
Thank you Tchaithonov. This is exactly what I need and it works.