面板數據回歸:R語言code


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 正相關,且顯著;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM