我有一个不平衡的面板数据集。以下数据将用于说明:
Id <- c(rep(1:4,3),rep(5,2))
Id <- Id[order(Id)]
Year <- c(rep(2000:2002,4),c(2000,2002))
z1 <- rnorm(14)
z2 <- rnorm(14)
z3 <- rnorm(14)
z4 <- rnorm(14)
CORR <- rbind(c(1,0.6,0.5,0.2),c(0.6,1,0.7,0.3),c(0.5,0.7,1,0.4),c(0.2,0.3,0.4,1))
CholCORR <- chol(CORR)
DataTest <- as.data.frame(cbind(z1,z2,z3,z4)%*%CholCORR)
names(DataTest)<-c("y","x1","x2","x3")
DataTest <- cbind(Id, Year, DataTest)
DataTest
Id Year y x1 x2 x3
1 1 2000 -0.7463355 -1.1920928 -1.2358912 -0.2527170
2 1 2001 -0.3475260 -0.1729497 -0.6252036 0.4366446
3 1 2002 0.6815678 0.1775869 0.2860103 0.8479373
4 2 2000 0.7927199 1.2830142 1.7018747 2.4475020
5 2 2001 0.5157535 0.4365100 1.1512340 1.0882581
6 2 2002 -1.2806121 0.3392759 0.5781835 0.2829615
7 3 2000 1.8741119 0.3904028 0.7984584 -1.7015025
8 3 2001 -0.4799960 0.6397883 0.4719150 0.8601328
9 3 2002 -2.2031991 0.3789198 -0.1143526 0.6771387
10 4 2000 -1.0634857 -0.6171644 -0.5732400 0.7718195
11 4 2001 0.3266059 -0.6882776 -0.2013544 -0.7242561
12 4 2002 0.2921222 -0.5149802 0.6180026 -0.4417939
13 5 2000 -2.2447755 -1.3328675 -1.6370130 0.4537451
14 5 2002 -0.9959034 -0.5958327 -0.3408927 0.2162799
我想为每年做一个横截面线性回归(3 个回归)并保存估计的系数,但由于面板不平衡(Id
5 缺少 2001 年的观察Year
)这一事实而变得复杂,因为我想估计以下与lag
和的动态公式diff
:
formula(diff(y) ~ lag(x1) + x2 + x3)
我曾想过使用plm
、reshape
或包,但是当我想使用我的不平衡面板plyr
时,我找不到有效的方法。lag
diff
谢谢,
米