stata,sas ,自变量中有一个是分组变量怎么回归

如题,回归方程中,因变量和其他自变量均为连续的面板数据,而自变量中,有一个变量为分组变量,请问应该怎么回归?
例如,将卖空率ratio根据size分为small,medium,large。

在SAS 中可以试试
proc glm data = data ordr = data (或 freq);
class ratio;
model y = x1 x2 ratio /solution;
run;
这里proc glm will generate dummy variables for a categorical variable, 所以不需要自己code manually (就像楼上朋友的回答)。
其中 order= 是选定哪个level为base line。如果你用 ordr = data,那么需要先对你的data进行排序,比如
proc sort data= data; by ratio descending (或ascending);run;
若使用 order = freq,则order the levels of class variable according to descending frequency count so that levels with the most observations come first in the order。
order = 可能还有别的选项,但我只用过=data 或 freq这两个,你可以google一下。
Does it work?
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-25
增加两个哑变量addsize1、addsize2如何?
if ratio=“small” then addsize1=1 ;else addsize1=0;
if ratio=“medium” then addsize2=1 ;else addsize2=0;
相似回答