SPClusterSE | R Documentation |
Function which calculates one-way or two-way clustered standard errors for a regression model. This function is basically a copy of Mahmood Ara's work (http://www.ne.su.se/polopoly_fs/1.216115.1426234213!/menu/standard/file/clustering1.pdf), as described by Kevin Goulding (https://thetarzan.wordpress.com/2011/06/11/clustered-standard-errors-in-r/). The example is also adapted from Kevin's excellent post.
SPClusterSE(Data = NA, Model, ClusterVar1, ClusterVar2 = NA, DFCorrection = 1)
Data |
A dataframe containing the data the regression is run in. Defaults to NA for two-way case. |
Model |
A saved regression model. |
ClusterVar1 |
The (first) variable to cluster by. |
ClusterVar2 |
The second variable to cluster by. Defaults to NA. |
DFCorrection |
A degree of freedom correction when the model was estimated on deviation from group mean data. Defaults to 1. |
require(foreign)
nmar <- read.dta("https://www.montana.edu/cstoddard/562/wr-nevermar.dta")
# Run a plain linear regression
regt <- lm(nevermar ~ impdum, data = nmar)
# apply the 'SPClusterSE' function by choosing a variable to cluster on.
# here, we are clustering on state.
SPClusterSE(Data = nmar, Model = regt, ClusterVar1 = nmar$state)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.