ols: This function is a wrapper around 'lm' and 'coeftest'

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ols.R

Description

This function is a wrapper around lm and coeftest

Usage

1
2
ols(..., HC = "const", cluster = NULL, data_frame = FALSE,
  as_attr = TRUE)

Arguments

...

(required) arguments passed to lm

HC

the HC matrix to be used for the robust standard error calculations

cluster

the name of the cluster variable in the data.frame passed to lm for the cluster robust standard error calculations

data_frame

return estimates in a data.frame or coeftest object(default)

as_attr

return R^2 and N as column or attributes when data_frame=TRUE?

Details

This function calls lm() and passes the model object further to coeftest() to calculate (cluster robust) standard errors. The results are equivalent to calling coeftest(model, vcov=vcovHC(m,HC)) or cl(model,cluster) after estimating model via lm().

The default settings produce estimates that are identical to calling lm(...).

To reproduce STATA's default robust standard errors use HC="HC1", to reproduce the STATA cluster robust standard errors (, vce(cluster ___)), supply the name of the cluster variable.

Value

a data.frame if data_frame=TRUE otherwise a coeftest object. The data.frame object has two additional attributes "N" (the number of observations) and "r2" the R^2 of the model.

Author(s)

The cluster robust standard error function cl() by Mahmood Ara at Stockholm University, see: https://thetarzan.wordpress.com/2011/06/11/clustered-standard-errors-in-r/

See Also

lm, vcovHC

Examples

1
2
3
4
5
6
7
8
x <- runif(100, -1, 1)
 g <- sample(1:10, 100, replace=TRUE)
 y <- 1 + x + rnorm(100)

 dat <- data.frame(y=y,x=x,g=g)
 dat[1,1] <- NA; dat[10,1] <- NA

 ols(y~x,dat=dat,cluster='g', na.action='na.omit')

sumtxt/datatools documentation built on Oct. 7, 2018, 11:18 p.m.