Regression by groups


Fortran must die
Anyone know a quick way to do one regression for every group, so for example if you have a variable called unit and you want to run a separate regression for each unit you can do this all at once rather than running one by one?


Not a robit
So say Unit = j groups, you want to subsample your sample into j subsamples. Then you want to run j regressions and get j outputs.

If yes, then you could in SAS place a WHERE statement in your PROC LOGISTIC and have a macro feeds it the group numbers and you could use an outest=est to get estimates then concatenate the results and do a proc print.


Not a robit
Here is a toy example that may get you started:

%let N = 20000;
%let Begin = 1;
%let Stop = 4;
data Noetsi;
        call streaminit(235);
        k = 4;
        do i = 1 to &N;
            Group = ceil(k * rand("Uniform"));
            U    = rand("Bernoulli", 0.6);
            C    = rand("Bernoulli", 0.4);
            X    = rand("Bernoulli", 0.35 + 0.2*C + 0.15*U);
            Y    = rand("Bernoulli", 0.05 + 0.05*X + 0.2*C + 0.05*X*C + 0.2*U);     
proc print data=noetsi (obs=10);

%MACRO Sets(Start, Stop);
%DO ID_set = &START %TO &STOP; 
proc logistic data=noetsi outest=est_&id_set;
    where group = &id_set;
    class     U (ref='0') 
            C (ref='0') 
            X (ref='0') / param=ref;
    model Y (event="1") = U C X;
%MEND Sets;

data coef;
    set est_&begin - est_&stop;
    keep U1    C1 X1;
proc print data=coef;


Fortran must die
Hslmith when you do multilevel modeling how do you do the analysis of the residuals and qq plots at the 2nd or higher level? Proc Reg and other methods have ways of getting these automatically, but I have not found a way to request this for multilevel models.


Not a robit
You posted that macro that had some output features. I do about 1-2 MLM a year. So it is always hard to remember. That and it is always for a binomial outcome.

Nothing gets kicked out with residual options or ods graphics on; ?

P.S., And most of the time when I test to see if group level effects explain a significant amount of variability it doesn't so I revert back to fix effects with robust SEs.