Robust Standard Errors in Stargazer

In a previous post, we discussed how to obtain robust standard errors in R. While the previous post described how one can easily calculate robust standard errors in R, this post shows how one can include robust standard errors in stargazer and create nice tables including robust standard errors.

I prepared a short tutorial to explain how to include robust standard errors in stargazer. The following R code does the following. First, it loads the function that is necessary to compute robust standard errors. Second, it downloads an example data set from this blog that is used to perform the OLS estimation and thirdly, it calculates a simple linear model using OLS. Finally, the script uses the summary.lm() function, the one that we loaded at the beginning, to calculate and recover STATA like robust standard errors and passes them on to the stargazer function. In the example I print the stargazer output as text, however, one replace can the argument type to “tex” or “html” in order to obtain perfectly formatted tex or html tables.

# start with an empty workspace

# load necessary packages for importing the function
# load necessary packages for the example

# import the robust standard error function
url_robust <- ""
eval(parse(text = getURL(url_robust, ssl.verifypeer = FALSE)),

# download data set for example
url_data <- ""
data <- read.xls(gsub("s:",":",url_data))

# estimate simple linear model
reg <- lm(weight ~ lag_calories+lag_cycling+

# use new summary function
summary(reg,robust = T)

# create stargazer output with robust standard errors

# save robust standard errors
robust_se <- as.vector(summary(reg,robust = T)$coefficients[,"Std. Error"])

# print stargazer output with robust standard errors
stargazer(reg,type = "text",se = list(robust_se))

# the last command prints the stargazer output (in this case as text)
# with robust standard errors. 

This entry was posted in Computing and Others, Econometrics and tagged , , , , . Bookmark the permalink.

One Response to Robust Standard Errors in Stargazer

  1. Pingback: Robust Standard Errors in R | Economic Theory Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.