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. > ## ---------------------------------------------------------------------------- > ## Baltagi (2002) -> Boot and De Wit (1960) > ## > ## data > ## availability: electronic > ## firms: General Motors, US Steel, General Electric, Chrysler, Atlantic Refining, > ## IBM, Union Oil, Westinghouse, Goodyear, Diamond Match > ## errors: none > ## note: grunfeld.dat was provided on disk for 1st edition, > ## on Springer Web page afterwards > ## > ## analysis > ## result: all results can be exactly reproduced, but taking lags is wrong > ## ---------------------------------------------------------------------------- > > ## preliminaries > 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 > > ## Exercise 10.9, p. 263 (independent of edition) > ## - consider first 3 firms (General Motors, US Steel, General Electric) > ## - 1st and 2nd edition ask to: run OLS of I on a constant, F_{-1}, C_{-1} > ## - 3rd edition asks to: run OLS of I on a constant, F, C > ## The solutions manual (Baltagi 1998, pp. 211) follows the 1st and 2nd edition > ## and erroneously lags the regressors. For replication of the solutions manual > ## we follow the erroneous approach. > > gr <- subset(Grunfeld, firm %in% c("General Motors", "US Steel", "General Electric")) > gr$firm <- factor(gr$firm) > gr$value1 <- c(NA, gr$value[1:59]) > gr$capital1 <- c(NA, gr$capital[1:59]) > gr <- gr[-c(1, 21, 41),] > pgr <- plm.data(gr, c("firm", "year")) > > ## (a) separate regressions, (b) test for serial correlation > lm_GM <- lm(invest ~ value1 + capital1, data = gr, subset = firm == "General Motors") > summary(lm_GM) Call: lm(formula = invest ~ value1 + capital1, data = gr, subset = firm == "General Motors") Residuals: Min 1Q Median 3Q Max -288.858 -76.371 1.897 97.316 211.411 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -72.90648 153.99802 -0.473 0.6423 value1 0.10142 0.03711 2.733 0.0147 * capital1 0.46585 0.06227 7.481 1.31e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 131.2 on 16 degrees of freedom Multiple R-squared: 0.8411, Adjusted R-squared: 0.8212 F-statistic: 42.33 on 2 and 16 DF, p-value: 4.072e-07 > dwtest(lm_GM) Durbin-Watson test data: lm_GM DW = 1.3985, p-value = 0.04442 alternative hypothesis: true autocorrelation is greater than 0 > t(sapply(1:3, function(x) bgtest(lm_GM, order = x)[c("statistic", "p.value")])) statistic p.value [1,] 2.624225 0.1052439 [2,] 2.959237 0.2277245 [3,] 3.846754 0.2784945 > vcov(lm_GM) (Intercept) value1 capital1 (Intercept) 23715.3914390 -5.4652248987 0.9078247414 value1 -5.4652249 0.0013768903 -0.0007264237 capital1 0.9078247 -0.0007264237 0.0038773611 > > lm_US <- lm(invest ~ value1 + capital1, data = gr, subset = firm == "US Steel") > summary(lm_US) Call: lm(formula = invest ~ value1 + capital1, data = gr, subset = firm == "US Steel") Residuals: Min 1Q Median 3Q Max -183.57 -70.85 11.89 66.93 198.83 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 306.27371 185.22724 1.654 0.118 value1 0.01502 0.09126 0.165 0.871 capital1 0.30988 0.21040 1.473 0.160 Residual standard error: 118.5 on 16 degrees of freedom Multiple R-squared: 0.1238, Adjusted R-squared: 0.01425 F-statistic: 1.13 on 2 and 16 DF, p-value: 0.3475 > dwtest(lm_US) Durbin-Watson test data: lm_US DW = 1.1116, p-value = 0.00879 alternative hypothesis: true autocorrelation is greater than 0 > t(sapply(1:3, function(x) bgtest(lm_US, order = x)[c("statistic", "p.value")])) statistic p.value [1,] 4.628508 0.03144489 [2,] 10.70952 0.004725596 [3,] 10.8666 0.01246953 > vcov(lm_US) (Intercept) value1 capital1 (Intercept) 34309.129267 -15.871433221 -8.702731269 value1 -15.871433 0.008327998 -0.001769902 capital1 -8.702731 -0.001769902 0.044267973 > > lm_GE <- lm(invest ~ value1 + capital1, data = gr, subset = firm == "General Electric") > summary(lm_GE) Call: lm(formula = invest ~ value1 + capital1, data = gr, subset = firm == "General Electric") Residuals: Min 1Q Median 3Q Max -48.228 -23.296 2.942 12.150 59.420 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -14.64958 39.69267 -0.369 0.717 value1 0.03151 0.01893 1.665 0.115 capital1 0.16230 0.03113 5.213 8.53e-05 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 29.99 on 16 degrees of freedom Multiple R-squared: 0.6385, Adjusted R-squared: 0.5933 F-statistic: 14.13 on 2 and 16 DF, p-value: 0.0002916 > dwtest(lm_GE) Durbin-Watson test data: lm_GE DW = 1.2413, p-value = 0.01597 alternative hypothesis: true autocorrelation is greater than 0 > t(sapply(1:3, function(x) bgtest(lm_GE, order = x)[c("statistic", "p.value")])) statistic p.value [1,] 2.774223 0.09579315 [2,] 8.61892 0.01344081 [3,] 11.25414 0.01042809 > vcov(lm_GE) (Intercept) value1 capital1 (Intercept) 1575.5078379 -7.066808e-01 -4.986645e-01 value1 -0.7066808 3.581721e-04 7.152997e-05 capital1 -0.4986645 7.152997e-05 9.691442e-04 > > ## visualization > plot(ts(residuals(lm_GM), start = 1936), type = "n", ylim = c(-300, 300), + xlab = "Year", ylab = "Residual") > abline(h = -2:2 * 100, col= "lightgray", lty = 2) > lines(ts(residuals(lm_GM), start = 1936), type = "b", pch = 22, lty = 1) > lines(ts(residuals(lm_US), start = 1936), type = "b", pch = 2, lty = 2) > lines(ts(residuals(lm_GE), start = 1936), type = "b", pch = 8, lty = 6) > legend("topleft", c("General Motors", "US Steel", "General Electric"), + lty = c(1, 2, 6), pch = c(22, 2, 8), bty = "n") > > ## (c) SUR for first 2 firms > pgr2 <- subset(pgr, firm %in% c("General Motors", "US Steel")) > pgr2$firm <- factor(pgr2$firm) > sf_SUR2 <- systemfit(invest ~ value1 + capital1, method = "SUR", data = pgr2) > summary(sf_SUR2) systemfit results method: SUR N DF SSR detRCov OLS-R2 McElroy-R2 system 38 32 500025 241453514 0.748546 0.734568 N DF SSR MSE RMSE R2 Adj R2 General.Motors 19 16 275321 17207.6 131.178 0.841049 0.821180 US.Steel 19 16 224704 14044.0 118.507 0.123713 0.014177 The covariance matrix of the residuals used for estimation General.Motors US.Steel General.Motors 17206.184 -355.933 US.Steel -355.933 14043.039 The covariance matrix of the residuals General.Motors US.Steel General.Motors 17207.564 -457.967 US.Steel -457.967 14044.013 The correlations of the residuals General.Motors US.Steel General.Motors 1.0000000 -0.0294597 US.Steel -0.0294597 1.0000000 SUR estimates for 'General.Motors' (equation 1) Model Formula: General.Motors_invest ~ General.Motors_value1 + General.Motors_capital1 Estimate Std. Error t value Pr(>|t|) (Intercept) -74.7762537 153.9745561 -0.48564 0.633806 value1 0.1015943 0.0371006 2.73835 0.014579 * capital1 0.4678608 0.0622631 7.51425 1.2378e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 131.177605 on 16 degrees of freedom Number of observations: 19 Degrees of Freedom: 16 SSR: 275321.024283 MSE: 17207.564018 Root MSE: 131.177605 Multiple R-Squared: 0.841049 Adjusted R-Squared: 0.82118 SUR estimates for 'US.Steel' (equation 2) Model Formula: US.Steel_invest ~ US.Steel_value1 + US.Steel_capital1 Estimate Std. Error t value Pr(>|t|) (Intercept) 309.9789866 185.1986384 1.67376 0.11361 value1 0.0125084 0.0912435 0.13709 0.89267 capital1 0.3143388 0.2103821 1.49413 0.15460 Residual standard error: 118.507437 on 16 degrees of freedom Number of observations: 19 Degrees of Freedom: 16 SSR: 224704.20367 MSE: 14044.012729 Root MSE: 118.507437 Multiple R-Squared: 0.123713 Adjusted R-Squared: 0.014177 > ## details: covariance/correlation matrices > summary(sf_SUR2)$residCovEst General.Motors US.Steel General.Motors 17206.1838 -355.9331 US.Steel -355.9331 14043.0394 > cov2cor(summary(sf_SUR2)$residCovEst) General.Motors US.Steel General.Motors 1.00000000 -0.02289790 US.Steel -0.02289790 1.00000000 > solve(cov2cor(summary(sf_SUR2)$residCovEst)) General.Motors US.Steel General.Motors 1.00052459 0.02290991 US.Steel 0.02290991 1.00052459 > solve(summary(sf_SUR2)$residCovEst) General.Motors US.Steel General.Motors 5.814913e-05 1.473841e-06 US.Steel 1.473841e-06 7.124701e-05 > > ## (d) SUR for first 3 firms > sf_SUR3 <- systemfit(invest ~ value1 + capital1, method = "SUR", data = pgr) > summary(sf_SUR3) systemfit results method: SUR N DF SSR detRCov OLS-R2 McElroy-R2 system 57 48 518965 1.07096e+11 0.744144 0.661296 N DF SSR MSE RMSE R2 Adj R2 General.Electric 19 16 15173.8 948.361 30.7955 0.618839 0.571194 General.Motors 19 16 277709.4 17356.835 131.7453 0.839670 0.819629 US.Steel 19 16 226081.6 14130.099 118.8701 0.118341 0.008134 The covariance matrix of the residuals used for estimation General.Electric General.Motors US.Steel General.Electric 899.427 1432.384 1857.441 General.Motors 1432.384 17206.184 -355.933 US.Steel 1857.441 -355.933 14043.039 The covariance matrix of the residuals General.Electric General.Motors US.Steel General.Electric 948.361 1619.449 2209.667 General.Motors 1619.449 17356.835 -484.286 US.Steel 2209.667 -484.286 14130.099 The correlations of the residuals General.Electric General.Motors US.Steel General.Electric 1.000000 0.3991582 0.6036252 General.Motors 0.399158 1.0000000 -0.0309239 US.Steel 0.603625 -0.0309239 1.0000000 SUR estimates for 'General.Electric' (equation 1) Model Formula: General.Electric_invest ~ General.Electric_value1 + General.Electric_capital1 Estimate Std. Error t value Pr(>|t|) (Intercept) -27.0247924 35.4446659 -0.76245 0.45688529 value1 0.0421470 0.0165788 2.54223 0.02174200 * capital1 0.1414154 0.0291337 4.85401 0.00017588 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 30.795473 on 16 degrees of freedom Number of observations: 19 Degrees of Freedom: 16 SSR: 15173.778091 MSE: 948.361131 Root MSE: 30.795473 Multiple R-Squared: 0.618839 Adjusted R-Squared: 0.571194 SUR estimates for 'General.Motors' (equation 2) Model Formula: General.Motors_invest ~ General.Motors_value1 + General.Motors_capital1 Estimate Std. Error t value Pr(>|t|) (Intercept) -27.6162396 147.6216963 -0.18707 0.853954 value1 0.0887317 0.0353665 2.50892 0.023253 * capital1 0.4815355 0.0615465 7.82393 7.3927e-07 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 131.745343 on 16 degrees of freedom Number of observations: 19 Degrees of Freedom: 16 SSR: 277709.366629 MSE: 17356.835414 Root MSE: 131.745343 Multiple R-Squared: 0.83967 Adjusted R-Squared: 0.819629 SUR estimates for 'US.Steel' (equation 3) Model Formula: US.Steel_invest ~ US.Steel_value1 + US.Steel_capital1 Estimate Std. Error t value Pr(>|t|) (Intercept) 255.5233390 167.0116275 1.52997 0.145553 value1 0.0347105 0.0817668 0.42451 0.676850 capital1 0.3537566 0.1955291 1.80923 0.089242 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 118.870093 on 16 degrees of freedom Number of observations: 19 Degrees of Freedom: 16 SSR: 226081.582434 MSE: 14130.098902 Root MSE: 118.870093 Multiple R-Squared: 0.118341 Adjusted R-Squared: 0.008134 > ## details: covariance/correlation matrices > summary(sf_SUR3)$residCovEst General.Electric General.Motors US.Steel General.Electric 899.4272 1432.3839 1857.4411 General.Motors 1432.3839 17206.1838 -355.9331 US.Steel 1857.4411 -355.9331 14043.0394 > cov2cor(summary(sf_SUR3)$residCovEst) General.Electric General.Motors US.Steel General.Electric 1.0000000 0.36411128 0.52263861 General.Motors 0.3641113 1.00000000 -0.02289790 US.Steel 0.5226386 -0.02289790 1.00000000 > solve(cov2cor(summary(sf_SUR3)$residCovEst)) General.Electric General.Motors US.Steel General.Electric 1.7084100 -0.6428335 -0.9076006 General.Motors -0.6428335 1.2424073 0.3644181 US.Steel -0.9076006 0.3644181 1.4826915 > solve(summary(sf_SUR3)$residCovEst) General.Electric General.Motors US.Steel General.Electric 0.0018994423 -1.634080e-04 -2.553767e-04 General.Motors -0.0001634080 7.220703e-05 2.344375e-05 US.Steel -0.0002553767 2.344375e-05 1.055820e-04 >