#Load libraries library("sandwich") library("lmtest") #Load Data data <- read.csv("C:/Users/Benja/Downloads/2008V2020Difference.csv" , header=TRUE, sep=",") #Run ordinary least squares ols <- lm(Difference ~ Dominion, data = data) # Test non-weighted regular standard error summary(ols) # Test non-weighted robust standard error coeftest(ols, vcov = sandwich) # Run weighted least squares wls <- lm(Difference ~ Dominion, weight = TotalVotes, data = data) # Test coefficent using regular standard error summary(wls) #Test coefficient using robust standard error coeftest(wls, vcov = sandwich, cluster = ~ TotalVotes)