My panel dataset contains 7 variables and 1452 observations, covering 6 years. I would like to regress y on x, while controlling for the other variables. The data contains quite a lot of missing observations, 35 % for the independent variable, x, and 23 % for the dependent one, y.
a, b, and c also contain missings but not to that extent.
A toy dataset looks like this:
Name | Year | id | y | x | a | b | c |
---|---|---|---|---|---|---|---|
A | 2015 | 1 | 6 | n.a. | 9 | 4 | 1 |
A | 2016 | 1 | n.a. | 2 | 9 | 3 | n.a. |
I used multiple imputation as provided by the mice function, which worked well. Diagnostics of the distributions of the imputed datasets also seem to be okay. Here is my code (excluding the diagnostics):
predictormatrix<-quickpred(data,
include=c("a", "b", "c", "x", "y"),
exclude=c("Name", "Year", "id"),
mincor = 0.1)
imp <- mice(data,
predictorMatrix = predictormatrix,
m=5,
maxit=5,
meth='pmm')
I can manage to conduct a simple pooled regression:
fitimp <- with(imp,
lm(y ~ x + a + b + c))
summary(pool(fitimp))
However, as a pooled OLS does not take into account the structure of the panel data, I would like to fit a fixed effects and a random effects model and decide on a model on the basis of the Hausman test. I tried using the with
function like this:
fitimp.fe <- with(imp,
plm(y ~ x + a + b + c),
data = imp,
index = c("Name", "Year"),
effect = "individual", model = "within")
summary(pool(fitimp.fe))
But it gives me an error: No tidy method for objects of class mids.
Plus a warning: Infinite sample size assumed.
Apart from fitting a fixed and random effects model to the imputed datasets, I do not know how to compare them (as mentioned, e.g., on the basis of a Hausman test). Can this be done with the with
function?
I've been trying to solve this for quite some time now and would be very grateful if someone could help me. I found a lot about imputation for multilevel data, but if I understood it correctly, this does not apply to my dataset. Last but not least, I've read multiple times to install broom.mixed
, which didn't help.