# Tests of R function using Mitchell Petersen's test-data # Read the data test <- read.table( url(paste("http://www.kellogg.northwestern.edu/", "faculty/petersen/htm/papers/se/", "test_data.txt",sep="")), col.names=c("firmid", "year", "x", "y")) # The fitted model fm <- lm(y ~ x, data=test) # Tests library(sandwich); library(lmtest) coeftest(fm) # OLS coeftest(fm, vcov=vcovHC(fm, type="HC0")) # White coeftest.cluster(test,fm, cluster1="firmid") # Clustered by firm coeftest.cluster(test,fm, cluster1="year") # Clustered by year coeftest.cluster(test,fm, cluster1="firmid", cluster2="year") # Clustered by firm and year