title: R - Plm and lm - Fixed effects
body: <p>I have a balanced panel data set, <em>df</em>, that essentially consists in three variables, <em>A</em>, <em>B</em> and <em>Y</em>, that vary over time for a bunch of uniquely identified regions. I would like to run a regression that includes both regional (region in the equation below) and time (year) fixed effects. If I'm not mistaken, I can achieve this in different ways:</p>
  
  <pre><code>lm(Y ~ A + B + factor(region) + factor(year), data = df)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>library(plm)
  plm(Y ~ A + B, 
      data = df, index = c('region', 'year'), model = 'within',
      effect = 'twoways')
  </code></pre>
  
  <p>In the second equation I specify indices (<em>region</em> and <em>year</em>), the model type ('within', FE), and the nature of FE ('twoways', meaning that I'm including both region and time FE).</p>
  
  <p>Despite I seem to be doing things correctly, I get extremely different results. The problem disappears when I do <strong>not</strong> consider time fixed effects - and use the argument <em>effect = 'individual'</em>. 
  What's the deal here? Am I missing something? Are there any other R packages that allow to run the same analysis?</p>