Also available in Stata and Python versions
Load libraries
library(wooldridge)
library(stargazer)
library(AER)
library(plm)
library(plyr)
RE Estimation of the Effects of Job Training Grants)
jtrainP <- pdata.frame(jtrain, index = c("fcode", "year"))
summary(RE <- plm(lscrap ~ d88 + d89 + union + grant + grant_1, data = jtrainP, model = "random"))
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = lscrap ~ d88 + d89 + union + grant + grant_1, data = jtrainP,
## model = "random")
##
## Balanced Panel: n = 54, T = 3, N = 162
##
## Effects:
## var std.dev share
## idiosyncratic 0.2477 0.4977 0.114
## individual 1.9322 1.3900 0.886
## theta: 0.7975
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -2.546798 -0.223892 0.040554 0.255287 1.549792
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 0.414833 0.243432 1.7041 0.08836 .
## d88 -0.093452 0.109156 -0.8561 0.39192
## d89 -0.269834 0.131650 -2.0496 0.04040 *
## union 0.547802 0.410625 1.3341 0.18218
## grant -0.214696 0.147784 -1.4528 0.14629
## grant_1 -0.377070 0.205352 -1.8362 0.06633 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 45.509
## Residual Sum of Squares: 38.798
## R-Squared: 0.14748
## Adj. R-Squared: 0.12015
## Chisq: 26.9867 on 5 DF, p-value: 5.7383e-05
linearHypothesis(RE, c("grant=0","grant_1=0"))
## Linear hypothesis test
##
## Hypothesis:
## grant = 0
## grant_1 = 0
##
## Model 1: restricted model
## Model 2: lscrap ~ d88 + d89 + union + grant + grant_1
##
## Res.Df Df Chisq Pr(>Chisq)
## 1 158
## 2 156 2 3.6645 0.1601
FE Estimation of the Effects of Job Training Grants
summary(FE <- plm(lscrap ~ 1 + d88 + d89 + union + grant + grant_1, data = subset(jtrainP), model = "within"))
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = lscrap ~ 1 + d88 + d89 + union + grant + grant_1,
## data = subset(jtrainP), model = "within")
##
## Balanced Panel: n = 54, T = 3, N = 162
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -2.286936 -0.112387 -0.017841 0.144272 1.426674
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## d88 -0.080216 0.109475 -0.7327 0.46537
## d89 -0.247203 0.133218 -1.8556 0.06634 .
## grant -0.252315 0.150629 -1.6751 0.09692 .
## grant_1 -0.421590 0.210200 -2.0057 0.04749 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 32.25
## Residual Sum of Squares: 25.766
## R-Squared: 0.20105
## Adj. R-Squared: -0.23684
## F-statistic: 6.54259 on 4 and 104 DF, p-value: 9.7741e-05
FE2 <- plm(lscrap ~ 1 + d88 + d89 + union , data = subset(jtrainP), model = "within")
pFtest(FE, FE2)
##
## F test for individual effects
##
## data: lscrap ~ 1 + d88 + d89 + union + grant + grant_1
## F = 2.2294, df1 = 2, df2 = 104, p-value = 0.1127
## alternative hypothesis: significant effects
Continued pp.311
summary(FEr <- plm(lscrap ~ d88 + d89 + union + grant + grant_1, data = subset(jtrainP), model = "within"))
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = lscrap ~ d88 + d89 + union + grant + grant_1, data = subset(jtrainP),
## model = "within")
##
## Balanced Panel: n = 54, T = 3, N = 162
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -2.286936 -0.112387 -0.017841 0.144272 1.426674
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## d88 -0.080216 0.109475 -0.7327 0.46537
## d89 -0.247203 0.133218 -1.8556 0.06634 .
## grant -0.252315 0.150629 -1.6751 0.09692 .
## grant_1 -0.421590 0.210200 -2.0057 0.04749 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 32.25
## Residual Sum of Squares: 25.766
## R-Squared: 0.20105
## Adj. R-Squared: -0.23684
## F-statistic: 6.54259 on 4 and 104 DF, p-value: 9.7741e-05
coeftest(FEr, vcovHC(FEr, type = "HC3"))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## d88 -0.080216 0.097776 -0.8204 0.41387
## d89 -0.247203 0.196769 -1.2563 0.21182
## grant -0.252315 0.143810 -1.7545 0.08229 .
## grant_1 -0.421590 0.283686 -1.4861 0.14028
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
FD Estimation of the Effects of Job Training Grants
jtrainP<- subset(jtrainP, !is.na(clscrap))
summary(FD <- lm(clscrap ~ d89 + cgrant + cgrant_1, data=jtrainP))
##
## Call:
## lm(formula = clscrap ~ d89 + cgrant + cgrant_1, data = jtrainP)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.12737 -0.13682 0.07311 0.26191 2.48850
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.09061 0.09097 -0.996 0.3216
## d89 -0.09621 0.12545 -0.767 0.4449
## cgrant -0.22278 0.13074 -1.704 0.0914 .
## cgrant_1 -0.35125 0.23508 -1.494 0.1382
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5767 on 104 degrees of freedom
## Multiple R-squared: 0.03652, Adjusted R-squared: 0.008725
## F-statistic: 1.314 on 3 and 104 DF, p-value: 0.2739
linearHypothesis(FD, c("cgrant=0","cgrant_1=0")) #Test
## Linear hypothesis test
##
## Hypothesis:
## cgrant = 0
## cgrant_1 = 0
##
## Model 1: restricted model
## Model 2: clscrap ~ d89 + cgrant + cgrant_1
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 106 35.608
## 2 104 34.590 2 1.0174 1.5295 0.2215
coeftest(FD, vcovHC(FD, type = "HC1")) #Robust
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.090607 0.084692 -1.0698 0.28717
## d89 -0.096208 0.128468 -0.7489 0.45562
## cgrant -0.222781 0.123865 -1.7986 0.07499 .
## cgrant_1 -0.351246 0.247722 -1.4179 0.15921
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
continued pp.320
u <- resid(FD <- lm(clscrap ~ d89 + cgrant + cgrant_1, data=jtrain))
jtrain2<- subset(jtrain, !is.na(clscrap))
jtrain2 <- cbind(jtrain2, u)
jtrain2 <- ddply(
jtrain2, .(fcode), transform,
u1 = c(NA, u[-length(u)])
)
ureg<- lm(u ~ u1, data=jtrain2)
stargazer(ureg, no.space=TRUE, type="text")
##
## ===============================================
## Dependent variable:
## ---------------------------
## u
## -----------------------------------------------
## u1 0.237*
## (0.135)
## Constant 0.000
## (0.076)
## -----------------------------------------------
## Observations 54
## R2 0.056
## Adjusted R2 0.038
## Residual Std. Error 0.560 (df = 52)
## F Statistic 3.096* (df = 1; 52)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01