Heteroskedasticity-Robust Standard Errors in Median Regressions

Does anyone know how to compute heteroskedasticity-robust standard errors in median regressions in R?

Assume the following example:

require("quantreg")

df <- iris
rq(Sepal.Length ~ Sepal.Width + Petal.Length, data = df)


I know that summary.rq offers multiple standard error options. But I do not know which option is the right one in my case. I would like to use the standard errors that Stata employs:

sysuse auto.dta
qreg price mpg trunk, vce(robust)


When running linear regressions in R, I correct standard errors with coeftest:

# Load packages
packs <- list("quantreg", "lmtest", "sandwich")
lapply(packs, require, character.only = T)

df <- iris
rq_outp <- lm(Sepal.Length ~ Sepal.Width + Petal.Length, data = df)
coeftest(rq_outp, vcov = vcovHC(rq_outp, type = "HC1"))


However, coeftest does apparently not work on rq objects.

• Thanks. In that case, what does Stata's vce(robust) do? It definitely changes standard errors. – Chr Nov 20 '20 at 19:17
• @BigBendRegion: do you want to post your comment(s) as an answer? Better to have a short answer than no answer at all. Anyone who has a better answer can post it. – kjetil b halvorsen Nov 22 '20 at 15:22
• @Chr, my guess would have been option option "nid", see also stata.com/features/overview/quantile-regression. Have you tried if it replicates the Stata results? – Christoph Hanck Nov 24 '20 at 8:02
• I did indeed compare the standard errors in R with those in Stata using an example. R's non-adjusted standard errors were the same as the ones Stata produces with vce(robust). However, they were different from standard errors that Stata generates without the vce(robust) option. – Chr Nov 24 '20 at 9:50