How to loop regressions?

Reply
N/A
Posts: 1

How to loop regressions?

Dear all,

I hope you would not mind my beginner question and could help me out of this problem or I will have to manually loop it myself. T_T

My sitution is that I have 10 independent (e.g. A,B,C,D,E,F,G,H,I,J, I will call them "AtoJ") variables and 1 dependent variable, my task is to run regressions of different combination of independent variables.

The combinations are, taking away one independent variable at a time, and run 10 regression, so the first one will be "AtoJ-A", then "AtoJ-B", "AtoJ-C" and so on.

Then I will have to take two indepentdent variable at a time, so "AtoJ-AB", "AtoJ-AC" and "AtoJ-AD" and so on. (How many regressions do I have to run for that?)

I have two questions,

Firstly, how to do that as in what command I should be using?

Secondly, I want to be able to see the result of the regressions, not only the estimators, but also t-stat, F-stat(anova), test of normailty and VIF. Is that possible?

Thanks in advance for your kind support, I hope I have expressed my situation clearly.

Bryan

Respected Advisor
Posts: 4,816

Re: How to loop regressions?

You could write all the models to a temporary file and then read in the code into proc reg. All the stats will be gathered in the outest= dataset

filename regCode temp;

data _null_;

length list $200;

set myData;

array vars a--j;

file regCode;

do ii = 1 to dim(vars);

    list = cats("M_",ii,":model myDep =");

    do kk = 1 to dim(vars);

        if kk ne ii then list = catx(" ", list, vname(vars{kk}));

        end;

    list = cats(list, ";");

    put list;

    do jj = ii+1 to dim(vars);

        list = cats("M_",ii,"_",jj,":model myDep =");

        do kk = 1 to dim(vars);

            if kk ne ii and kk ne jj then list = catx(" ", list, vname(vars{kk}));

            end;

        list = cats(list, ";");

        put list;

        end;

    end;

stop;

run;

proc reg data=myData plots=none tableout outest=myStats;

var a--j;

%include regCode;

run;

quit;

(not fully tested)

PG

PG
Ask a Question
Discussion stats
  • 1 reply
  • 192 views
  • 3 likes
  • 2 in conversation