廢話不多說,直接附上code
影片含有程式碼詳細解說,若有誤再煩請告知,謝謝
library(plm)
data("Produc")
panel_data = pdata.frame(Produc, index = c("state","year"))
#選模型: within(固定),random(隨機)
#選依據: individual,time,twoways
固定 <- plm(pcap ~ pc ,
model = c("within"), effect = c("time"),
data = panel_data)
隨機 <- plm(pcap ~ pc ,
model = c("random"), effect = c("time"),
data = panel_data)
phtest(固定, 隨機)#<0.05 用within
model <- plm(pcap ~ pc ,
model = c("within"),
effect = c("time"),
data = panel_data)
summary(model)