SPClusterSE: SPClusterSE

View source: R/SPClusterSE.R

SPClusterSER Documentation

SPClusterSE

Description

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.

Usage

SPClusterSE(Data = NA, Model, ClusterVar1, ClusterVar2 = NA, DFCorrection = 1)

Arguments

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.

Examples

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)


stpalan/SPTools documentation built on Aug. 21, 2023, 11:21 a.m.