### R code from vignette source 'Lab1.snw' ################################################### ### code chunk number 1: typo ################################################### print("hello") ################################################### ### code chunk number 2: init ################################################### library(plm) ################################################### ### code chunk number 3: exgrun ################################################### data(Grunfeld) head(Grunfeld) ?Grunfeld ################################################### ### code chunk number 4: classes ################################################### class(Grunfeld) str(Grunfeld) ################################################### ### code chunk number 5: estsyntax ################################################### femod <- plm(formula=inv~value+capital, data=Grunfeld) femod1 <- plm(formula=inv~value+capital, data=Grunfeld, index=c("firm","year")) ################################################### ### code chunk number 6: randreorder ################################################### grun0 <- Grunfeld[, order(rnorm(dim(Grunfeld)[[2]]))] head(grun0) ################################################### ### code chunk number 7: pdata ################################################### pgrun <- pdata.frame(Grunfeld, index=c("firm", "year")) class(pgrun) str(pgrun) summary(pgrun) class(pgrun$capital) str(pgrun$capital) ################################################### ### code chunk number 8: ldiff ################################################### capital.1 <- lag(pgrun$capital) d.capital <- diff(pgrun$capital) head(capital.1) head(d.capital) head(pgrun$capital) ################################################### ### code chunk number 9: formula ################################################### fm <- inv~value+capital ################################################### ### code chunk number 10: lm ################################################### olsmod <- lm(formula=fm, data=Grunfeld) class(olsmod) ################################################### ### code chunk number 11: summ ################################################### summary(olsmod) library(lmtest) coeftest(olsmod) coef(olsmod)["capital"] ################################################### ### code chunk number 12: roblm ################################################### library(sandwich) coeftest(olsmod, vcov=vcovHC) ################################################### ### code chunk number 13: lht ################################################### library(car) linearHypothesis(olsmod, "2*value=capital", vcov=vcovHC) ################################################### ### code chunk number 14: plm1 ################################################### poolmod <- plm(fm, data=Grunfeld, model="pooling") class(poolmod) coeftest(poolmod) ################################################### ### code chunk number 15: plmhc1 ################################################### coeftest(poolmod, vcov=vcovHC) ################################################### ### code chunk number 16: plmhc2 ################################################### coeftest(olsmod, vcov=vcovHC) coeftest(poolmod, vcov=function(x) vcovHC(x, method="white1", type="HC3")) ################################################### ### code chunk number 17: poollag ################################################### poolAR1mod <- plm(update(fm, .~.+lag(inv)), data=Grunfeld, model="pooling") ################################################### ### code chunk number 18: poolfd ################################################### dfm <- diff(inv)~diff(value)+diff(capital) poolfdmod <- plm(dfm, data=Grunfeld, model="pooling") ################################################### ### code chunk number 19: fdmod ################################################### fdmod <- plm(fm, data=Grunfeld, model="fd")