# Loading the required libraries library(plm) library(lmtest) library(multiwayvcov) # Loading Petersen's dataset data(petersen) # Pooled OLS model pooled.ols <- plm(formula=y~x, data=petersen, model="pooling", index=c("firmid", "year")) # Fixed effects model fe.firm <- plm(formula=y~x, data=petersen, model="within", index=c("firmid", "year")) # Clustered standard errors - OLS (by firm) coeftest(pooled.ols, vcov=vcovHC(pooled.ols, type="sss", cluster="group")) # Clustered standard errors - OLS (by time) coeftest(pooled.ols, vcov=vcovHC(pooled.ols, type="sss", cluster="time")) # Clustered standard errors - OLS (by firm and time) coeftest(pooled.ols, vcov=vcovDC(pooled.ols, type="sss")) # Clustered standard errors - Fixed effect regression (by firm) coeftest(fe.firm, vcov=vcovHC(fe.firm, type="sss", cluster="group")) # Clustered standard errors - Fixed effect regression (by time) coeftest(fe.firm, vcov=vcovHC(fe.firm, type="sss", cluster="time")) # Clustered standard errors - Fixed effect regression (by firm and time) coeftest(fe.firm, vcov=vcovDC(fe.firm, type="sss"))