R version 2.10.1 (2009-12-14) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## ---------------------------------------------------------------------------- > ## Swamy (1970) > ## > ## data > ## availability: none > ## firms: General Motors, US Steel, General Electric, Chrysler, Atlantic Refining, > ## IBM, Union Oil, Westinghouse, Goodyear, Diamond Match, American Steel > ## errors: claims to use all firms and that data are from Boot and de Wit 1960, > ## but this is impossible given that they only have 10 firms. > ## > ## analysis > ## result: uses all 11 firms > ## ---------------------------------------------------------------------------- > > > ## Sect. 7 > ## test stat. given below (7.3) claims to use F_(20,187) crit. value > ## but this should perhaps be F_(20,198) according to theory on p. 319 > ## if data are demeaned (Lambda=2 vs Lambda=3) > > source("start.R") Loading required package: kinship Loading required package: survival Loading required package: splines Loading required package: nlme Loading required package: lattice [1] "kinship is loaded" Loading required package: Formula Loading required package: MASS Loading required package: sandwich Loading required package: zoo Loading required package: Matrix Loading required package: car Loading required package: lmtest > > gr <- Grunfeld > gr$firm <- factor(gr$firm) > pgr <- plm.data(gr, c("firm", "year")) > > ## RCM without demeaning: > fm_rcm <- pvcm(invest ~ value + capital, model = "random", data = pgr) > summary(fm_rcm) Oneway (individual) effect Random coefficients model Call: pvcm(formula = invest ~ value + capital, data = pgr, model = "random") Balanced Panel: n=11, T=20, N=220 Residuals: Min. 1st Qu. Median Mean 3rd Qu. Max. -202.000 -26.030 -2.865 10.700 11.360 602.200 Estimated mean of the coefficients: Estimate Std. Error z-value Pr(>|z|) (Intercept) -9.226403 15.390778 -0.5995 0.5488555 value 0.083550 0.018479 4.5214 6.142e-06 *** capital 0.191523 0.049367 3.8796 0.0001046 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Estimated variance of the coefficients: (Intercept) value capital (Intercept) 2141.68301 -0.66038974 -3.83117197 value -0.66039 0.00286624 -0.00078343 capital -3.83117 -0.00078343 0.02336957 Total Sum of Squares: 485460000 Residual Sum of Squares: 2261200 Multiple R-Squared: 0.99534 > coeftest(fm_rcm)[2:3, 1:2] Estimate Std. Error value 0.08354966 0.01847858 capital 0.19152270 0.04936711 > > ## demeaning > pgrd <- pgr > pgrd[,3:5] <- with(pgr, apply(pgr[,3:5], 2, function(x) resid(lm(x ~ firm)))) > > ## RCM with demeaning (without constant) > fm_rcmd <- pvcm(invest ~ 0 + value + capital, model = "random", data = pgrd) > summary(fm_rcmd) Oneway (individual) effect Random coefficients model Call: pvcm(formula = invest ~ 0 + value + capital, data = pgrd, model = "random") Balanced Panel: n=11, T=20, N=220 Residuals: Min. 1st Qu. Median Mean 3rd Qu. Max. -1.892e+02 -1.051e+01 -6.889e-01 -3.774e-16 7.036e+00 4.778e+02 Estimated mean of the coefficients: Estimate Std. Error z-value Pr(>|z|) value 0.074805 0.014164 5.2812 1.283e-07 *** capital 0.194324 0.044854 4.3324 1.475e-05 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Estimated variance of the coefficients: value capital value 0.00121647 -0.00025917 capital -0.00025917 0.01897987 Total Sum of Squares: 36102000 Residual Sum of Squares: 745280 Multiple R-Squared: 0.97936 > coeftest(fm_rcmd)[, 1:2] Estimate Std. Error value 0.07480489 0.01416435 capital 0.19432422 0.04485392 >