title: Prediction using Fixed Effects
body: <p>I have a simple data set for which I applied a simple linear regression model. Now I would like to use fixed effects to make a better prediction on the model. I know that I could also consider making dummy variables, but my real dataset consist of more years and has more variables so I would like to avoid making dummies.</p>
  
  <p>My data and code is similar to this:</p>
  
  <pre><code>data &lt;- read.table(header = TRUE, 
                     stringsAsFactors = FALSE, 
                     text="CompanyNumber ResponseVariable Year ExplanatoryVariable1 ExplanatoryVariable2
                     1 2.5 2000 1 2
                     1 4 2001 3 1
                     1 3 2002 5 7
                     2 1 2000 3 2
                     2 2.4 2001 0 4
                     2 6 2002 2 9
                     3 10 2000 8 3")
  
  library(lfe)
  library(caret)
  fe &lt;- getfe(felm(data = data, ResponseVariable ~ ExplanatoryVariable1 + ExplanatoryVariable2 | Year))
  fe
  lm.1&lt;-lm(ResponseVariable ~ ExplanatoryVariable1 + ExplanatoryVariable2, data=data)                                   
  
  
  prediction&lt;- predict(lm.1, data) 
  prediction
  
  check_model=postResample(pred = prediction, obs = data$ResponseVariable)
  check_model
  </code></pre>
  
  <p>For my real dataset I will make a prediction based on my test set but for simplicity I just use the trainingset here as well.</p>
  
  <p>I would like to make a prediction with the help of the fixed effects that I found. But it does not seem to match the fixed effect right, anyone who knows how to use this <code>fe$effects</code>?</p>
  
  <pre><code>prediction_fe&lt;- predict(lm.1, data) + fe$effect
  </code></pre>