Page 1 of 1

Error in if code

Posted: Tue Jun 21, 2011 5:51 am
by kansas
Hi,
I need to select subsets from a variable list and run regressions on it.
my variable set is x1 x2 x3..... x10
first i select all variables without x1 and run the regression
in the next iteration i select all variables without x1 and run the regression.
Also im keeping position in which the minimum SE occured.

I wrote the following code.
But an error occurs when i try to increase the number of variables. It works perfectly upto 9 variables. But gives an error "NA found in matrix in".
i have marked the location as 'ERROR HAPPENS HERE" in the code.

Any guidance would be highly appreciated.

Code: Select all

group t_group x1 x2 x3 x4 x5 x6 x7 x8 x9 scalar position=0 !loop_count= 1 for %y 1 2 3 4 5 6 7 8 9 group t_ for !j=1 to t_group.@count if !j<>{%y} then t_.add t_group(!j) endif next equation eq{%y}.ls Y c t_ eq{%y}.makeresid res_ids{%y} 'creating residuals coef max_er if {%y}=1 then max_er=eq{%y}.@se position=!loop_count else if max_er>eq{%y}.@se then 'ERROR HAPPENS HERE max_er=eq{%y}.@se position=!loop_count endif endif next

Re: Error in if code

Posted: Tue Jun 21, 2011 8:30 am
by EViews Gareth
I'm not getting the errors you're getting, so I'm not sure what is going on for you.

However, I will point out a possible bug in your code. Each time through the loop you're declaring a group called _T, and then adding variables to it. However when you re-declare a group, EViews doesn't wipe out the existing variables in it. Thus each time through the loop, the group is getting bigger and bigger as you're re-adding the same variables to it over and over. You should probably delete the group at the end of your loop.

Re: Error in if code

Posted: Tue Jun 21, 2011 9:31 am
by kansas
Hi
thanks for the quick reply. I added a delete statement for that group.
But still im getting the error.
I have attached the full code herewith.
the code works perfectly when i define the group as

Code: Select all

group g x1 x2 x3 x4 x5 x6 x7 x8 x9
but fails when

Code: Select all

group g x1 x2 x3 x4 x5 x6 x7 x8 x9 x10

any ideas ?

Re: Error in if code

Posted: Tue Jun 21, 2011 9:40 am
by EViews Gareth
You only have 10 observations. If you run a regression with 10 regressors, you will get a perfect fit, thus standard errors will be NAs.

Re: Error in if code

Posted: Tue Jun 21, 2011 11:17 am
by kansas
thanks. I didnt notice that. I created a random dataset to test my code segment . Now it works.

i have one more question on this .
im saving adf coeeficients in order to get the minimum coefficient position(row) from the table.

Code: Select all

adf_coefs(%y,1) = mytable{%y}(7,4) 'saving coefficients to a table
i used following code to get the minimum. But it gives me the maximum value.

Code: Select all

!min_position=1 for !u=2 to t_group.@count if adf_coefs(!u,1)<adf_coefs(!min_position,1) then ' get the minimum coefficient position !min_position=!u endif next

Does eviews ignore the negativeness of ADF coefficients ?

full code and data are attached.

Thanks alot.

Re: Error in if code

Posted: Tue Jun 21, 2011 11:49 am
by EViews Gareth
Somewhat subtle, but...

A table does not contain numbers. Rather it contains the string representation of numbers. Thus doing inequality tests on the cells of a table will give unexpected results.

Two options. Either store the values in a matrix rather than a table (since a matrix holds numbers), or convert the cells of the table into numbers before doing the inequality test, using the @val function:

Code: Select all

if @val(adf_coefs(!u,1))<@val(adf_coefs(!min_position,1)) then

Re: Error in if code

Posted: Tue Jun 21, 2011 11:57 am
by kansas
thanks a bunch.
That solved my problem. :)