#Load libraries library("sandwich") library("lmtest") #Load Data data <- read.csv("C:/Users/Benja/Downloads/DvDData.csv" , header=TRUE, sep=",") #Run ordinary least squares ols <- lm(Difference ~ RuralUrbanContinuumCode2013 + ManufacturingDependent2000 + HiAmenity + HiCreativeClass2000 + Low_Education_2015_update + PopChangeRate1019 + Net_International_Migration_Rate_2010_2019 + Dominion, data = data) # Test non-weighted regular standard error summary(ols) # Test non-weighted using robust standard error coeftest(ols, vcov = sandwich) # Run weighted least squares wls <- lm(Difference ~ RuralUrbanContinuumCode2013 + ManufacturingDependent2000 + HiAmenity + HiCreativeClass2000 + Low_Education_2015_update + PopChangeRate1019 + Net_International_Migration_Rate_2010_2019 + 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)