Error in if code

For questions regarding programming in the EViews programming language.

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

kansas
Posts: 4
Joined: Tue Jun 21, 2011 5:35 am

Error in if code

Postby kansas » Tue Jun 21, 2011 5:51 am

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
Attachments
Book1.csv
data file
(1.31 KiB) Downloaded 295 times

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

Re: Error in if code

Postby EViews Gareth » Tue Jun 21, 2011 8:30 am

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.

kansas
Posts: 4
Joined: Tue Jun 21, 2011 5:35 am

Re: Error in if code

Postby kansas » Tue Jun 21, 2011 9:31 am

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 ?
Attachments
full code.prg
full code
(714 Bytes) Downloaded 312 times

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

Re: Error in if code

Postby EViews Gareth » Tue Jun 21, 2011 9:40 am

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.

kansas
Posts: 4
Joined: Tue Jun 21, 2011 5:35 am

Re: Error in if code

Postby kansas » Tue Jun 21, 2011 11:17 am

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.
Attachments
Book2.csv
dataset
(43.95 KiB) Downloaded 274 times
code3.prg
code
(1.09 KiB) Downloaded 304 times

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

Re: Error in if code

Postby EViews Gareth » Tue Jun 21, 2011 11:49 am

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

kansas
Posts: 4
Joined: Tue Jun 21, 2011 5:35 am

Re: Error in if code

Postby kansas » Tue Jun 21, 2011 11:57 am

thanks a bunch.
That solved my problem. :)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests