I am trying to replicate the results provided by the Stata command xtscc
in R with package plm
but I am having some trouble to see the same standard errors
I am using a dataset from the package plm also in Stata for replication purposes.
# code to obtain dataset
library(lmtest)
library(car)
library(tidyverse)
data("Produc", package="plm")
write.dta(Produc,"test.dta")
My aim is to run a two way-fixed effect panel model estimation with Driscoll and Kraay standard errors. The routine in Stata is the following
use "test.dta", clear \\ to import data
** i declare the panel
xtset state year
* create the dummies for the time fixed effects
quietly tab year, gen(yeardum)
* run a two way fixed effect regression model with Driscoll and Kraay standard errors
xi: xtscc gsp pcap emp unemp yeardum*,fe
* results are the following
Coef. Std. Err. t P>|t| [95% Conf. Interval]
pcap | -.1769881 .265713 -0.67 0.515 -.7402745 .3862983
emp | 40.61522 2.238392 18.14 0.000 35.87004 45.3604
unemp | 23.59849 85.10647 0.28 0.785 -156.8192 204.0161
In R I use the following routine:
# I declare the panel
Produc <- pdata.frame(Produc, index = c("state","year"), drop.index = FALSE)
# run a two way fixed effect model
femodel <- plm(gsp~pcap+emp+unemp, data=Produc,effect = "twoway",
index = c("iso3c","year"), model="within")
# compute Driscoll and Kraay standard errors using vcovSCC
coeftest(femodel, vcovSCC(femodel))
pcap -0.17699 0.25476 -0.6947 0.4874
emp 40.61522 2.14610 18.9252 <2e-16 ***
unemp 23.59849 81.59730 0.2892 0.7725
While point estimates are the same that in Stata, standard errors are different.
To check whether I am using the "wrong" small sample adjustment for standard errors, I also tryed running the coeftest with all available adjustments, but none yields the same values as xtscc
.
library(purrr)
results <- map(c("HC0", "sss", "HC1", "HC2", "HC3", "HC4"),~coeftest(femodel, vcovSCC(femodel,type = .x)))
walk(results,print)
# none of the estimated standard errors is the same as xtscc
Does anyone know how I can replicate the results of Stata in R?
plm::within_intercept
to see how the FE model with an intercept is calculated (documentation was references). I suspectxtssc
somehow uses Stata'sxtreg
. I don't know ifxtssc
uses the same small sample adjustment asxtreg
. – Helix123xtscc
is afaik a user contributed command. If its documentation does not reveal the small sample adjustment employed, you might want to read the functions source code or contact its author. In plm, type =sss
mimics Stata's small sample adjustment (hence its name). – Helix123index
argument in your call toplm
is ignored as your data is already a pdata.frame. Also, the index argument contains a variable not in the data (iso3c
). – Helix123