vcovTamal: Group clustering of panel data esitmates

Description Usage Arguments Details Value Note Author(s) References Examples

Description

vcovTamal, creates a robust covariance variance matrix clustered at group level for first difference estimations of the lm::plm command. Clustering is based on Angist and Pischke (2009) resulting in Stata(TM) like standard errors of regression coefficients.

Usage

1
vcovTamal(estimate, data, groupvar, byhand = F)

Arguments

estimate

an object of class plm estimated with the fd option in methods.

data

a data.frame object, that must be the data.frame used to create the plm object. Can be a data.frame or a pdata.frame object.

groupvar

a string indicating a column in data that indicates the group structure.

byhand

logical, if TRUE, the clustered covariance matrix is calculated by formulas without using the multiwayvcov package. This method is outdated.

Details

See package vignette.

Value

A matrix containing the covariance matrix estimate

Note

The function uses the plm output and the data to construct a transfomed (first differenced) data frame. The esitmate is then re-estimated by OLS with lm in order to extract the covarinace matrix and correct for degrees of freedom and use a sandwich estimate with the group structure. The implementation for Fixed Effects (within) estimates is outdated. Ihe command felm of the package lfe is able construct directly estimates with multiple cluster with multiple fixed effects.

Author(s)

ElĂ­as Cisneros <ec@elias-cisneros.de>

References

Angrist, J. D. & Pischke, J.-S. Mostly harmless econometrics: An empiricist's companion Princeton university press, 2009 Arai, M. Cluster-robust standard errors using R, 2015. See also: https://thetarzan.wordpress.com/2011/06/11/clustered-standard-errors-in-r/.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
##packages
library(foreign)
library(clubTamal)
library(lmtest)
library(plm)
library(clubSandwich)
library(spd4testing)
library(multiwayvcov)

##data
d<-spd4testing()
d

##formula
f<- formula(y ~ x + factor(year))

##standard estimation
e<-plm(formula=f,data=d,model="fd")
summary(e)
## Not run: 
  # e<-plm(formula=f,data=d,model="within")
  # summary(e)

## End(Not run)

##clustering
#no clustering
v<-e$vcov
coeftest(e)
#clustering at id level with plm-package
v<-vcovHC(e,type="HC1",cluster="group",tol=1*10^-20 )
coeftest(e,v)

##clustering at group level with clubSandwich-package
##only for Fixed Effects regressions
v<-vcovCR(e,d$gid,type="CR1")
coef_test(e,vcov=v,test="naive-t")
coeftest(e,v)

##clustering at group level with clubTamal
v<-vcovTamal(estimate=e,data=d,groupvar="gid")
coeftest(e,v)

##clustering with clubTamal but without using the multivcov package
## Not run: 
v<-vcovTamal(estimate=e,data=d,groupvar="gid",byhand=T)
coeftest(e,v)

## End(Not run)

##clustering at group level with STATA (TM)
#export data
tdir<-tempdir()
write.csv(d,file.path(tdir,"spd.csv"))
#write stata file
sink(file.path(tdir,"clusterStata.do"))
cat(paste0('insheet using "',file.path("spd.csv"),'", clear'))
cat("\n")
cat('xtset id year')
cat("\n")
cat('xtreg y x i.year, fe')
cat("\n")
cat('xtreg y x i.year, fe vce(cluster gid)')
cat("\n")
cat('reg d.y d.x i.year')
cat("\n")
cat('reg d.y d.x i.year, vce(cluster gid)')
sink()
## RUN Stata file

eliascis/clubTamal documentation built on May 17, 2019, 2:07 p.m.