title: fixed effects in R: plm vs lm + factor()
body: <p>I'm trying to run a fixed effects regression model in R. I want to control for heterogeneity in variables C and D (neither are a time variable). </p>
  
  <p>I tried the following two approaches:</p>
  
  <p>1) Use the plm package: Gives me the following error message</p>
  
  <pre><code>formula = Y ~ A + B + C + D
  
  reg = plm(formula, data= data, index=c('C','D'), method = 'within')
  
  duplicate couples (time-id)Error in pdim.default(index[[1]], index[[2]]) : 
  </code></pre>
  
  <p>I also tried creating first a panel using </p>
  
  <pre><code>data_p = pdata.frame(data,index=c('C','D'))
  </code></pre>
  
  <p>But I have repeated observations in both columns.</p>
  
  <p>2) Use factor() and lm: works well</p>
  
  <pre><code>formula = Y ~ A + B + factor(C) + factor(D)
  reg = lm(formula, data= data)
  </code></pre>
  
  <p>What is the difference between the two methods? Why is plm not working for me? is it because one of the indices should be time?</p>