0

So I have seen questions regarding this error code before, but the suggested troubleshooting that worked for those authors didn't help me diagnose. I'm self-learning R and new to Stackoverflow, so please give me constructive feedback on how to better ask my question, and I will do my best to provide necessary information. I've seen many, similar questions put on hold so I want to help you to help me. I'm sure the error probably stems from my lack of experience in data prep.

I'm trying to run a panel data model, loaded as .csv and this error returns when the model is run

fixed = plm(Y ~ X, data=pdata, model = "within")

Error in `colnames<-`(`*tmp*`, value = "1") : 
  length of 'dimnames' [2] not equal to array extent

running str() on my dataset returns that ID and Time are factors with 162 levels and 7 levels, respectively.

str(pdata)
Classes ‘plm.dim’ and 'data.frame': 1127 obs. of  11 variables:
 $ ID                                    : Factor w/ 162 levels "1","2","3","4",..: 1 1 1 1 1 1 1 2 2 2 ...
 $ Time                                  : Factor w/ 7 levels "1","2","3","4",..: 1 2 3 4 5 6 7 1 2 3 ...
 $ Online.Service.Index                  : num  0.083 0.131 0.177 0.268 0.232 ...
 $ Eparticipation                        : num  0.0345 0.0328 0.0159 0.0454 0.0571 ...
 $ CPI                                   : num  2.5 2.6 2.5 1.5 1.4 0.8 1.2 2.5 2.5 2.4 ...
 $ GE.Est                                : num  -1.178 -0.883 -1.227 -1.478 -1.466 ...
 $ RL.Est                                : num  -1.67 -1.71 -1.72 -1.95 -1.9 ...
 $ LN.Pop                                : num  16.9 17 17 17.1 17.1 ...
 $ LN.GDP.Cap                            : num  5.32 5.42 5.55 5.95 6.35 ...
 $ Human.Capital.Index                   : num  0.268 0.268 0.268 0.329 0.364 ...
 $ Telecommunication.Infrastructure.Index: num  0.0016 0.00173 0.00202 0.01576 0.03278 ...

Still, I don't see how it would create this error. I've tried transforming it as a data frame or matrix, with the same result (I got desperate and it worked for some people)

dim() yields
[1] 1127   11

I have some NA values, but I understand that these shouldn't cause a problem. Again, I'm self-taught and new here, so please take it easy on me! Hope I explained the problem well.

Tony
  • 11
  • 3
  • 1
    I'm confused... your code uses `pdata` with `Y` and `X` yet you show `str(EGDI)`. – slamballais Jan 29 '16 at 11:20
  • @Laterow Thank you for pointing that out to me. for str(pdata) it tells me that $ID and $Time are Factor w/ 162 levels and Factor w/ 7 levels, respectively. I suppose that is where I went wrong? – Tony Jan 29 '16 at 11:29
  • I don't think that that's the problem, but you can try recoding (`p <- pdata; p$ID <- as.numeric(levels(p$ID))[p$ID]; p$Time <- as.numeric(levels(p$Time))[p$Time]`). Also, I'm [not so sure if you can use NAs](http://stackoverflow.com/questions/9592415/what-is-a-dimnames-error-when-estimating-gls). If recoding doesn't work, can you try running without NAs? – slamballais Jan 29 '16 at 11:41
  • @Laterow, okay I'll try one and then the other and let you know after dinner (I'm on Seoul time). I know Stata allows you to run an unbalanced panel with NAs and would prefer not to lose those observations, but that could be the case. Thanks! – Tony Jan 29 '16 at 11:47
  • 1
    "I have some NA values, but I understand that these shouldn't cause a problem." sounds like a dangerous assumption to me, especially when it's something easy to check. – NGaffney Jan 29 '16 at 11:53
  • where is `X`? I don't see it defined within `pdata` ... a reproducible example is always good! – Ben Bolker Jan 29 '16 at 13:08
  • looking at your 'str(pdata)', I think you need to convert your data to a `pdata.frame` first. – Helix123 Feb 10 '16 at 13:11

0 Answers0