Clustered Standard Errors in STATA

In STATA clustered standard errors are obtained by adding the option cluster(variable_name) to your regression, where variable_name specifies the variable that defines the group / cluster in your data. The summary output will return clustered standard errors. Here is the syntax:

 regress x y, cluster(variable_name)

Below you will find a tutorial that demonstrates how to calculate clustered standard errors in STATA. The tutorial is based on an simulated data that I generate here and which you can download here.

* start with an empty workspace
clear all

*import data into your STATA session
import excel using "https://economictheoryblog.com/wp-content/uploads/2016/12/data.xls",first

*OLS without clustered standard errors
regress id_score class_size

*OLS with clustered standard errors
regress id_score class_size, cluster(class_id)

* Note, the standard errors are much 
* larger with clustered standard errors

One thought on “Clustered Standard Errors in STATA”

Leave a comment

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