library(plm)
library(psych)
library(xts)
library(tseries)
library(lmtest)
## import dataset
datas<-read.table("data.txt",header =TRUE)
## adf test
pcgdp<-xts(datas$PCGDP,as.Date(datas$year))
adf.test(pcgdp)
# result: stationary
ltax<-xts(datas$Ltax,as.Date(datas$year))
adf.test(ltax)
# result: stationary
hp<-xts(datas$hp,as.Date(datas$year))
adf.test(hp)
# result: stationary
lp<-xts(datas$lp,as.Date(datas$year))
adf.test(lp)
# result: stationary
## 协整检验
# Engle-Granger
reg<-lm(datas$hp~datas$lp+datas$Ltax+datas$PCGDP)
summary(reg)
error<-residuals(reg)
adf.test(error)
# result: residuals stationary
### 面板数据回归
hpdatas<-plm.data(datas,index=c("city","year"))
# Pooled Regression Model
hp_pool<-plm(hp~lp+Ltax+PCGDP+PP,data=hpdatas,model = "pooling")
# Fixed Effects Regression Model
hp_fe<-plm(hp~lp+Ltax+PCGDP+PP,data=hpdatas,model = "within")
# F-test :
pFtest(hp_fe,hp_pool)
# result: significant effects
# Random Effects Regression Model
hp_re<-plm(hp~lp+Ltax+PCGDP,data=hpdatas,model="random",random.method = "swar")
# Hausman test
phtest(hp_fe,hp_re)
# if p<0.05,then use fixed effects
# result: p=0.6785>0.05,use random ffects
# Random Effects Regression Model
hp_re<-plm(hp~lp+Ltax+PCGDP,data=hpdatas,model="random",random.method = "swar")
summary(hp_re)
# 显著水平 a=0.01
# result: fp:房价与 lp:地价正相关,且显著;
# fp:房价与 Ltax: 地税收入正相关,且显著;
# fp:房价与 PCGDP: 人均GDP 正相关,且显著;
来源:https://www.cnblogs.com/laoketeng/p/11268581.html