> mdata <-read.table("panel.csv", header=T, sep=",") > id <-mdata[,1] > year<-mdata[,2] > y <-mdata[,3] > x <-mdata[,4] > ols_result <-lm(y~x) > summary(ols_result) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -2.52559 -0.39145 0.07648 0.51871 1.61471 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.43810 0.10262 14.01 <2e-16 *** x 0.84544 0.03498 24.17 <2e-16 *** --- Signif. codes: 0 e***f 0.001 e**f 0.01 e*f 0.05 e.f 0.1 e f 1 Residual standard error: 0.799 on 313 degrees of freedom Multiple R-squared: 0.6511, Adjusted R-squared: 0.65 F-statistic: 584.1 on 1 and 313 DF, p-value: < 2.2e-16 > mydata <-data.frame(id,year,y,x) > library(lattice) > xyplot(y[1:28]~year[1:28]|as.character(id[1:28]), data=mydata, xlab="year", ylab="y", type="l", as.table=TRUE) > xyplot(y[1:28]~year[1:28], groups=as.character(id[1:28]), data=mydata, xlab="year", ylab="y", type="l", as.table=TRUE, auto.key = list(x = 0.1, y = 0.8, corner = c(0, 0))) > library(plm) > fixed <-plm(y~x, data=mydata, index=c("id","year"), model="within") > summary(fixed) Oneway (individual) effect Within Model Call: plm(formula = y ~ x, data = mydata, model = "within", index = c("id", "year")) Balanced Panel: n = 45, T = 7, N = 315 Residuals: Min. 1st Qu. Median 3rd Qu. Max. -1.2919733 -0.1525946 0.0088823 0.2231488 1.0914112 Coefficients: Estimate Std. Error t-value Pr(>|t|) x 0.195584 0.081855 2.3894 0.01757 * --- Signif. codes: 0 e***f 0.001 e**f 0.01 e*f 0.05 e.f 0.1 e f 1 Total Sum of Squares: 36.917 Residual Sum of Squares: 36.15 R-Squared: 0.020783 Adj. R-Squared: -0.14303 F-statistic: 5.70919 on 1 and 269 DF, p-value: 0.017565 > pFtest(fixed,pool) F test for individual effects data: y ~ x F = 27.683, df1 = 44, df2 = 269, p-value < 2.2e-16 alternative hypothesis: significant effects # fixed effects: alpha+u_i > summary(fixef(fixed)) Estimate Std. Error t-value Pr(>|t|) 1 3.28080 0.15422 21.2742 < 2.2e-16 *** 2 3.11843 0.29516 10.5653 < 2.2e-16 *** 3 3.02394 0.25892 11.6790 < 2.2e-16 *** 4 2.80321 0.20902 13.4113 < 2.2e-16 *** 5 4.26975 0.33127 12.8891 < 2.2e-16 *** 6 1.75536 0.26685 6.5780 2.475e-10 *** 7 2.72358 0.15102 18.0342 < 2.2e-16 *** 8 4.49926 0.35651 12.6202 < 2.2e-16 *** 9 3.76266 0.26940 13.9666 < 2.2e-16 *** 10 5.37197 0.40826 13.1582 < 2.2e-16 *** 11 2.74967 0.26812 10.2553 < 2.2e-16 *** 12 2.51395 0.21171 11.8744 < 2.2e-16 *** 13 3.20393 0.19897 16.1023 < 2.2e-16 *** 14 3.20121 0.25105 12.7513 < 2.2e-16 *** 15 2.85323 0.21248 13.4281 < 2.2e-16 *** 16 3.59978 0.28924 12.4457 < 2.2e-16 *** 17 3.12772 0.35804 8.7356 2.639e-16 *** 18 3.79249 0.32649 11.6161 < 2.2e-16 *** 19 3.92342 0.30444 12.8874 < 2.2e-16 *** 20 2.64026 0.26174 10.0872 < 2.2e-16 *** 21 1.84157 0.23136 7.9596 4.853e-14 *** 22 0.68081 0.20937 3.2517 0.001293 ** 23 4.29891 0.38487 11.1698 < 2.2e-16 *** 24 3.29837 0.24475 13.4766 < 2.2e-16 *** 25 3.55406 0.31790 11.1797 < 2.2e-16 *** 26 3.86666 0.22426 17.2416 < 2.2e-16 *** 27 3.88323 0.30878 12.5761 < 2.2e-16 *** 28 0.65306 0.14345 4.5524 8.042e-06 *** 29 2.94679 0.23379 12.6046 < 2.2e-16 *** 30 1.28630 0.17853 7.2052 5.843e-12 *** 31 5.10160 0.39886 12.7905 < 2.2e-16 *** 32 1.23127 0.14624 8.4197 2.278e-15 *** 33 2.40025 0.14390 16.6800 < 2.2e-16 *** 34 4.96925 0.42253 11.7608 < 2.2e-16 *** 35 0.92362 0.14194 6.5070 3.729e-10 *** 36 2.61346 0.19394 13.4754 < 2.2e-16 *** 37 4.51959 0.41697 10.8390 < 2.2e-16 *** 38 4.32519 0.31243 13.8437 < 2.2e-16 *** 39 2.36210 0.28097 8.4069 2.484e-15 *** 40 3.27609 0.28583 11.4618 < 2.2e-16 *** 41 2.90388 0.24818 11.7007 < 2.2e-16 *** 42 4.08466 0.28724 14.2204 < 2.2e-16 *** 43 3.58245 0.22082 16.2232 < 2.2e-16 *** 44 3.70293 0.30053 12.3213 < 2.2e-16 *** 45 3.28288 0.30251 10.8520 < 2.2e-16 *** --- Signif. codes: 0 e***f 0.001 e**f 0.01 e*f 0.05 e.f 0.1 e f 1 > random <-plm(y~x, data=mydata, index=c("id","year"), model="random") > summary(random) Oneway (individual) effect Random Effect Model (Swamy-Arora's transformation) Call: plm(formula = y ~ x, data = mydata, model = "random", index = c("id", "year")) Balanced Panel: n = 45, T = 7, N = 315 Effects: var std.dev share idiosyncratic 0.1344 0.3666 0.213 individual 0.4954 0.7038 0.787 theta: 0.8068 Residuals: Min. 1st Qu. Median 3rd Qu. Max. -1.358754 -0.206733 0.053443 0.251733 0.815222 Coefficients: Estimate Std. Error t-value Pr(>|t|) (Intercept) 2.29119 0.19784 11.5810 < 2.2e-16 *** x 0.52182 0.06180 8.4438 1.164e-15 *** --- Signif. codes: 0 e***f 0.001 e**f 0.01 e*f 0.05 e.f 0.1 e f 1 Total Sum of Squares: 56.909 Residual Sum of Squares: 46.351 R-Squared: 0.18553 Adj. R-Squared: 0.18292 F-statistic: 71.2972 on 1 and 313 DF, p-value: 1.1642e-15 > phtest(random, fixed) Hausman Test data: y ~ x chisq = 36.942, df = 1, p-value = 1.217e-09 alternative hypothesis: one model is inconsistent > pool <-plm(y~x, data=mydata, index=c("id","year"), model="pooling") > summary(pool) Pooling Model Call: plm(formula = y ~ x, data = mydata, model = "pooling", index = c("id", "year")) Balanced Panel: n = 45, T = 7, N = 315 Residuals: Min. 1st Qu. Median 3rd Qu. Max. -2.525593 -0.391450 0.076475 0.518710 1.614709 Coefficients: Estimate Std. Error t-value Pr(>|t|) (Intercept) 1.438101 0.102621 14.014 < 2.2e-16 *** x 0.845438 0.034983 24.167 < 2.2e-16 *** --- Signif. codes: 0 e***f 0.001 e**f 0.01 e*f 0.05 e.f 0.1 e f 1 Total Sum of Squares: 572.75 Residual Sum of Squares: 199.84 R-Squared: 0.65108 Adj. R-Squared: 0.64997 F-statistic: 584.061 on 1 and 313 DF, p-value: < 2.22e-16 > plmtest(pool, type=c("bp")) Lagrange Multiplier Test - (Breusch-Pagan) for balanced panels data: y ~ x chisq = 516.79, df = 1, p-value < 2.2e-16 alternative hypothesis: significant effects