用R語言做計量(二):面板回歸

# Panel Data Models in Rlibrary(plm)mydata <- read.csv("panel_wage.csv")attach(mydata)Y <- cbind(lwage)X <- cbind(exp, exp2, wks, ed)summary(Y)summary(X)ols <- lm(Y ~ X)summary(ols)#聲明面板#Stata: xtset pdata <- plm.data(mydata,indexes = c("id","t"))#混合回歸#Stata: regpooling <- plm(Y ~ X, data = pdata,model = "pooling") summary(pooling)#固定效應#Stata: xtreg ,fefixed <- plm(Y ~ X,data = pdata,model = "within") summary(fixed)#隨機效應#Stata: xtreg ,rerandom <- plm(Y ~ X,data = pdata,model = "random") summary(random)#不同模型的比較# random vs olsplmtest(pooling)# fixed vs olspFtest(fixed, pooling)# random vs fixedphtest(random, fixed)

推薦閱讀:

用R語言做計量(四):估計結果的導出

TAG:R編程語言 | 計量經濟 |