2

plm()用于合并 OLS时,是否可以包含分类变量(具有多个因子水平的因子) ?据我了解,plm()所有变量都必须是数字,这在我的情况下不起作用。我可以为每个因子水平包含一个虚拟变量,但是,这会导致更多的变量,而这些变量实际上只是更少因子的水平。

我在CrossValidated上提出了类似的问题,并感谢任何形式的帮助。

如果需要,我将包含一个最小的示例,但我认为这是一个关于如何使用plm()lm().

4

1 回答 1

1

plm()您可以在和中轻松包含数值变量和分类变量变量lm()

require(plm)
data(Males)
head(Males[1:6])
# nr year school exper union  ethn
# 1 13 1980     14     1    no other
# 2 13 1981     14     2   yes other
# 3 13 1982     14     3    no other
# 4 13 1983     14     4    no other
# 5 13 1984     14     5    no other
# 6 13 1985     14     6    no other

coef(lm(wage ~ school + union + ethn, data=Males))
# (Intercept)      school    unionyes   ethnblack    ethnhisp 
# 0.7148      0.0767      0.1930     -0.1523      0.0134 

coef(plm(wage ~ school + union + ethn, data=Males, model="pooling"))
# (Intercept)      school    unionyes   ethnblack    ethnhisp 
# 0.7148      0.0767      0.1930     -0.1523      0.0134 

如您所见,您可以在这两种情况下同时使用虚拟变量和分类变量。

于 2015-01-15T19:20:00.580 回答