I have been working on migrating a current project from Stata to R, where I have encountered difficulties with differing results of random effects regressions.
I have panel data from an experiment where the treatment dummy is perfectly correlated with the group indicator because it is time-invariant. This means that a fixed effects regression of the outcome variable on the treatment dummy is not possible – however, a random-effects regression should be, since it only partially time-demeans the data. I am willing to assume that the treatment dummy and other covariates are not correlated with the group-specific error.
In Stata, this worked without a problem. The random-effects regression of the continuous outcome variable on the treatment dummy gives a result that makes sense, and the fixed effects regression omits the treatment dummy, exactly as expected.
However, in R, using the plm package, it did not work. I have received the error message "empty model." Curiously, this is not the case if the model does not include the treatment-dummy but other variables as regressors that are not perfectly correlated with the group indicator. In this case, plm's default method "swar" gives the same results as Stata.
I have tried to use other methods that are supplied by plm, and only the "walhus" method does work. In the case of a regression with the treatment dummy as a covariate, this gives the same result on the coefficients as Stata. However, it gives different results for models without the treatment dummy. These differences are not huge but considerable.
So in conclusion, I am able to replicate Stata's results in R, but with different methods where Stata uses only one. I have not found an explanation for that behavior in the Stata Documentation or in the plm paper in the Journal of Statistical Software. The plm paper gives sources for the different methods for RE (that supposedly differ in their estimation of theta) but does not explain the differences itself. The original sources for "swar" and "walhus" are Econometrica papers from the late 60s / early 70s. Quite frankly, I was not able to find a solution in these either. I have also found this question on Stackexchange, but I believe that this is a different issue.
Any help or ideas would be much appreciated! This has already taken an immense ammount of time and I find it to be really troubling.
P.S. I cannot share the original data, but I have created a dataset with similar properties with which these problems can be replicated. I have put it into a dropbox, as .Rdata and .dta.
The "original" Stata code:
xtset GroupID Round
xtreg outcome Treatment, re
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
Treatment | 36.93656 5.97516 6.18 0.000 25.22546 48.64766
_cons | 51.16955 4.225076 12.11 0.000 42.88855 59.45055
-------------+----------------------------------------------------------------
xtreg outcome X1, re
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
X1 | -.0278302 .1193763 -0.23 0.816 -.2618033 .206143
_cons | 70.84536 6.953707 10.19 0.000 57.21635 84.47438
-------------+----------------------------------------------------------------
The corresponding R-code:
library(plm)
testdata <- pdata.frame(testdata, index=c("GroupID","Round"))
Model1 <- plm(outcome ~ Treatment, data = testdata, model="random", random.method="swar")
summary(Model1) # This doesn’t work
Error in plm.fit(data, model = models[1], effect = effect) : empty model
Model2 <- plm(outcome ~ Treatment, data = testdata, model="random", random.method="walhus")
summary(Model2) # This gives the same results as Stata
Estimate Std. Error z-value Pr(>|z|)
(Intercept) 51.1695 4.2251 12.1109 < 2.2e-16 ***
Treatment 36.9366 5.9752 6.1817 6.342e-10 ***
Model3 <- plm(outcome ~ X1, data = testdata, model="random", random.method="swar")
summary(Model3) # This gives the same results as Stata
Estimate Std. Error z-value Pr(>|z|)
(Intercept) 70.84536 6.95371 10.1881 <2e-16 ***
X1 -0.02783 0.11938 -0.2331 0.8157
Model4 <- plm(outcome ~ X1, data = testdata, model="random", random.method="walhus")
summary(Model4) # This gives slightly different results than Stata
Estimate Std. Error z-value Pr(>|z|)
(Intercept) 70.682277 7.003460 10.0925 <2e-16 ***
X1 -0.024072 0.119074 -0.2022 0.8398
EDIT: I have tried something else and found that plm's default method "swar" does also work for a model that includes both the time-invariant treatment-dummy and a time-varying continuous covariate:
Model1.2 <- plm(outcome ~ Treatment + X1, data = testdata, model="random", random.method="swar")
summary(Model1.2) # This somehow works
Estimate Std. Error z-value Pr(>|z|)
(Intercept) 14.906599 11.284649 1.3210 0.1865
Treatment 36.835123 6.075290 6.0631 1.335e-09 ***
X1 -0.012018 0.108785 -0.1105 0.9120
This gives the same results on the coefficients (but not the intercept) as Stata:
xtreg outcome Treatment X1, re
------------------------------------------------------------------------------
outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
Treatment | 36.83512 6.07529 6.06 0.000 24.92777 48.74247
X1 | -.012018 .1087849 -0.11 0.912 -.2252326 .2011965
_cons | 51.74172 6.697543 7.73 0.000 38.61478 64.86866
-------------+----------------------------------------------------------------