用R语言做面板数据回归:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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