title: Regression using plm package and twoways effect, when data has NA
body: <p>So, I'd like to run a regression on a panel data, using two-ways effects, for time and stores. If the panel is perfectly balanced, it works fine, but for some reason, if it's not, the code gets stuck. (see: <a href="https://stat.ethz.ch/pipermail/r-help/2010-May/239272.html" rel="nofollow noreferrer">https://stat.ethz.ch/pipermail/r-help/2010-May/239272.html</a>).</p>
  <p>My data in particular is not unbalanced in nature, but it has some NAs, so I guess it's becoming unbalanced when the plm function removes rows with NA.
  I wrote a sample code to exemplify the data I have.</p>
  <p>If I run this:</p>
  <pre><code>set.seed(123)
  library(plm)
  number.of.days &lt;- 1100
  number.of.stores &lt;- 1000
  days &lt;- sort(rep(c(1:number.of.days),number.of.stores))
  stores &lt;- rep(c(1:number.of.stores),number.of.days)
  
  data &lt;- cbind.data.frame(stores,days,matrix(rnorm(number.of.days*number.of.stores*7),nrow=number.of.days*number.of.stores,ncol=7))
  colnames(data)[3:9] &lt;- c('y',paste0('x',1:6))
  
  data &lt;- plm.data(data,c(&quot;stores&quot;,&quot;days&quot;))  
  fit &lt;- plm(y ~ x1 + x2 + x3 + x4 + x5 + x6, data = data, index=c(&quot;stores&quot;,&quot;days&quot;), effect=&quot;twoway&quot;, model=&quot;within&quot;)
  </code></pre>
  <p>It works correctly, because the panel is balanced. However, if I create some NA values:</p>
  <pre><code>data$y[sample(1:number.of.days*number.of.stores,150)] &lt;- NA
  data$x1[sample(1:number.of.days*number.of.stores,150)] &lt;- NA
  data$x2[sample(1:number.of.days*number.of.stores,150)] &lt;- NA
  data$x3[sample(1:number.of.days*number.of.stores,150)] &lt;- NA
  data$x4[sample(1:number.of.days*number.of.stores,150)] &lt;- NA
  data$x5[sample(1:number.of.days*number.of.stores,150)] &lt;- NA
  data$x6[sample(1:number.of.days*number.of.stores,150)] &lt;- NA
  </code></pre>
  <p>And try to run the regression again:</p>
  <pre><code> fit &lt;- plm(y ~ x1 + x2 + x3 + x4 + x5 + x6, data = data, index=c(&quot;stores&quot;,&quot;days&quot;), effect=&quot;twoway&quot;, model=&quot;within&quot;)
  </code></pre>
  <p>It does not work (the code apparently never stops running)</p>
  <p>I tried using 'individual' effect for stores and adding a matrix with dummies for time, but since there are 1100 days, it becomes just as slow.</p>
  <p>I assume this is not a rare problem. Is there any known solution?</p>
  <p>Thank you</p>