Search code examples
rplmstandard-errorrobust

R - fixed effect of panel data analysis and robust standard errors


I am working with the panel data through plm package in R. And now I am considering a fixed effect model of group (cities), time, and two ways of group and time, respectively. Because I detected heteroskedasticity through the Breusch-Pagan test, I compute robust standard errors.

I read a help ?vcovHC, but I could not understand fully how to utilize coeftest.

My current code is:

library(plm)
library(lmtest)
library(sandwich)

fem_city <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "individual")
fem_year <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "time")
fem_both <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "twoways")

coeftest(fem_city, vcovHC(fem_city, type = 'HC3', cluster = 'group')
coeftest(fem_year, vcovHC(fem_city, type = 'HC3', cluster = 'time')

In order to compute the robust standard errors, are codes of coeftest appropriate? I am wondering that how to set the cluster option for effect = 'individual and effect = 'time' each. For example, I set coeftest codes:

cluster = 'group' in plm of fem_city for effect = 'individual' in coeftest

cluster = 'time' in plm of fem_year for effect = 'time' in coeftest

Is this way appropriate?

And, how to compute the robust standard error for twoways of both city and year?


Solution

  • Set cluster='group' if you want to cluster on the variable serving as the individual index (city in your example).

    Set cluster='time' if you want to cluster on the variable serving as the time index (yearin your example).

    You can cluster on the time index even for a fixed effects one-way individual model.

    For clustering on both index variables, you cannot do that with plm::vcovHC. Look at vcovDC from the same packages which provides double clustering (DC = double clustering), e.g.,

    coeftest(fem_city, vcovDC(fem_city)