0
$\begingroup$

I'm trying to understand the difference between XTREG and PLM. First, I have looked at this answered question:

Difference between fixed effects models in R (plm) and Stata (xtreg)

But when I try the code provided by the answerer, I get different answers from R and Stata. The STATA results match those of the answerer, but the R results do not.

I have an inkling for why. When I execute that code in R, R doesn't create lags within the grouping variable, it creates lags overall. For example, if there are 50 states and 17 years, when including a lag in the regression, I will lose 50 observations: the first year for each state. In STATA, the sample size reduces accordingly. In R, the sample size reduces by 1. This is because its not identifying the "state" grouping variable. So, does anyone have an idea of what is going on here?

$\endgroup$
  • $\begingroup$ I've run the code using the most updated version of R and Stata 14 -they yielded the same results as one another and it matches the results in the link you posted. perhaps check your code against theirs once more and provide us with your sessionInfo() It would also help to provide us with the actual data you are using (if its different than the example from the link) $\endgroup$ – Cyrus Mohammadian Aug 25 '16 at 21:06
  • $\begingroup$ I used the exact code and data from the link. I had loaded the library dplyr before executing it. Could that alter the way that the lagging takes place? $\endgroup$ – Ralph M Aug 25 '16 at 21:39
0
$\begingroup$

The result of the error I was getting was due to dplyr being active. Once I detached this library, the code provided in plm matches that of xtreg.

$\endgroup$
  • $\begingroup$ You can also explicitly refer to lag of plm by plm::lag (as with any other function from other packages). $\endgroup$ – Helix123 Aug 26 '16 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.