Permutation of all Independent Variables

For questions regarding programming in the EViews programming language.

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

mrod305
Posts: 4
Joined: Mon Nov 28, 2011 12:09 pm

Permutation of all Independent Variables

Postby mrod305 » Mon Nov 28, 2011 12:14 pm

I have the following variables:

y, x1, x2, x3, x4

They are not a time series. They are an unstructured panel.

I want to run a program that gives me a linear regression with every possible permutation. I want to store R-squared, t-stats, and AIC.

The permutations should include regressions with one-to-many variables. For example I want the results as if I had typed in all of these:

y x1
y x1 x2
y x1 x2 x3
y x1 x2 x3 x4
y x1 x3
y x1 x4
y x2 x3
y x2 x3 x4
y x2 x4
....etc etc.

How do I write a program that will run that regression for me?

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

Re: Permutation of all Independent Variables

Postby EViews Gareth » Mon Nov 28, 2011 2:26 pm

I'm sure there is a more efficient method, but this seems to work:

Code: Select all

%vars1 = "x1 x2 x3 x4 " for %var1 {%vars1} for %var2 {%vars1} for %var3 {%vars1} for %var4 {%vars1} %vars = %var1 + " " + %var2 + " " + %var3 + " " + %var4 %vars = @wunique(%vars) %vars = @wsort(%vars) %eqname = "eq_" + @replace(%vars, " ", "_") if @isobject(%eqname) = 0 then equation {%eqname}.ls y {%vars} endif next next next next

mrod305
Posts: 4
Joined: Mon Nov 28, 2011 12:09 pm

Re: Permutation of all Independent Variables

Postby mrod305 » Wed Dec 14, 2011 8:55 am

In the course of the recursion, I get a "near singular matrix" error when it is trying to run one of the regression.

Is it possible to override this, so that if it gets the error, the recursion continues through?

The issue is that some of the permutations probably do have this error. But some do not. I don't want the entire process interrupted just because one of the regressions gives this error.

Thanks!

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

Re: Permutation of all Independent Variables

Postby EViews Gareth » Wed Dec 14, 2011 9:34 am

When you run your program, just set the maximum number of errors to something high.

mrod305
Posts: 4
Joined: Mon Nov 28, 2011 12:09 pm

Re: Permutation of all Independent Variables

Postby mrod305 » Wed Dec 14, 2011 10:02 am

How do I do that? I'm new to e-views programming, so what's syntax/command for that? Thanks!

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

Re: Permutation of all Independent Variables

Postby EViews Gareth » Wed Dec 14, 2011 10:11 am

When you hit the run button on your program there is an option to set the number of errors. It isn't a command - it is on the dialog.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests