Package 'ceser'

Title: Cluster Estimated Standard Errors
Description: Implementation of the Cluster Estimated Standard Errors (CESE) proposed in Jackson (2020) <DOI:10.1017/pan.2019.38> to compute clustered standard errors of linear coefficients in regression models with grouped data.
Authors: Diogo Ferrari [aut, cre]
Maintainer: Diogo Ferrari <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2025-01-31 03:53:56 UTC
Source: https://github.com/diogoferrari/ceser

Help Index


Sample data set

Description

A dataset relating the effective number of parties to the number of presidential candidates and presidential power.

Usage

dcese

Format

A data frame with rows and 9 variables:

country

name of the country

enep

Effective number of legislative parties

enpc

Number of presidential candidates

fapres

Presidential power

proximity

Proximity of the presidential and legislative elections

eneg

Eeffective number of ethnic groups

logmag

log of average district magnitudes

enpcfapres

Interaction between enpc and fapres

logmag_eneg

Interaction between logmag and eneg

...

Source

Jackson, John (2019) Corrected Standard Errors with Clustered Data. Political Analysis.

References

Elgie, Robert, Bueur, C., Dolez, B. & Laurent, A. (2014). “Proximity, Candidates, and Presidential Power: How Directly Elected Presidents Shape the Legislative Party System.” Political Research Quarterly. 67(3): 467 - 477.


Cluster Estimated Standard Errors

Description

Cluster Estimated Standard Errors (CESE)

Usage

vcovCESE(mod, cluster = NULL, type = NULL)

Arguments

mod

a model object. It can be the output of the functions lm, glm, or other regression function that returns compatible objects. Important: See details

cluster

either a string vector with the name of the variables that will be used to cluster the standard errors, or a formula - e.g., ~ rhs, with a summation of the variables that will be used to cluster the standard errors replacing the rhs -, or a vector, matrix, or data.frame with the clustering data.

type

string with either HC0, HC1, HC2, HC3, or HC4. It specifies the type of heteroskedasticity correction to use (see Davidson and MacKinnon (1993) and Hayes and Cai (2007)).

Details

The data frame must be ordered by the clustering variables before estimating the model with lm, etc.

Value

The function returns a variance-covariace matrix of the coefficient estimates using the Cluster Estimated Standard Error (CESE) method.

References

Jackson, John (2019) Corrected Standard Errors with Clustered Data. Political Analysis.

Hayes, A. F., & Cai, L., (2007) Using heteroskedasticity-consistent standard error estimators in ols regression: an introduction and software implementation, Behavior research methods, 39(4), 709–722.

Davidson, R., & MacKinnon, J. G., (2004) Econometric theory and methods: Oxford University Press New York.

Examples

mod  = lm(enep ~  enpc + fapres + enpcfapres + proximity + eneg + logmag + logmag_eneg , data=dcese)

## --------------------------------------
## Getting the variance covariance matrix
## -------------------------------------- 
## Original variance-covariance matrix (no clustered std. errors)
vcov(mod)

## Variance-covariance matrix using CRSE (sandwish package)
## sandwich::vcovCL(mod, cluster = ~ country)
## sandwich::vcovCL(mod, cluster = ~ country, type="HC3")

## Variance-covariance matrix using CESE
ceser::vcovCESE(mod, cluster = ~ country)
ceser::vcovCESE(mod, cluster = ~ country, type="HC3") # HC3 correction

## ---------
## Summaries
## ---------
## no robust SE 
summary(mod)                                                                          

## summary table using CRSE (sandwich package)
## lmtest::coeftest(mod, vcov = sandwich::vcovCL, cluster = ~ country)                   

## summary using CESE
lmtest::coeftest(mod, vcov = ceser::vcovCESE, cluster = ~ country, type='HC3')