|
sas分组回归例子
现有数据如下:
daima y x u man
1 11 0.5 0.6 上
1 10 0.3 0.6 上
1 10 0.3 0.8 上
1 7 0.4 0.7 下
1 6 0.7 0.6 下
1 9 0.7 1.1 下
2 11 0.5 0.4 中
2 10 0.3 0.8 中
2 6.5 0.35 0.65 中
现在以y为因变量,x,u为自变量进行回归分析,同时要按照daima相同并且man相同进行分组回归,比如,以上数据,所需要做的回归就有3组,第一组回归为daima为1并且man为上;第二组回归为daima为1,并且man为下;第三组回归为daima为2,并且man为中。
data test1;
input daima yxuman y x u man ;
cards;
1 11 0.5 0.6 上
1 10 0.3 0.6 上
1 10 0.3 0.8 上
1 7 0.4 0.7 下
1 6 0.7 0.6 下
1 9 0.7 1.1 下
2 11 0.5 0.4 中
2 10 0.3 0.8 中
2 6.5 0.35 0.65 中
;
proc sort data=test1;
by daima man;
run;
data test2;
set test1;
retain flag;
if lag(man)^=man then flag+1;
run;
proc reg data=test2;
model y=x u;
by flag;
run;
|