title: Merge plm fitted values to dataset
body: <p>I'm working with a fixed effects regression model using plm. </p>
  
  <p>The model looks like this:</p>
  
  <pre><code>FE.model &lt;-plm(fml, data = data.reg2,
             index=c('Site.ID','date.hour'), # cross section ID and time series ID
             model='within', #coefficients are fixed
             effect='individual')
  summary(FE.model)
  </code></pre>
  
  <p>"fml" is a formula I defined previously. I have many independent variables, so this made it more efficient.</p>
  
  <p>What I want to do is get my fitted values (my yhats) and join them to my base dataset; data.reg2</p>
  
  <p>I was able to get the fitted values using this code:</p>
  
  <pre><code> Fe.model.fitted &lt;- FE.model$model[[1]] - FE.model$residuals
  </code></pre>
  
  <p>However, this only gives me a one column vector of fitted values only - I have no way of joining it to my base dataset. </p>
  
  <p>Alternatively, I've tried something like this:</p>
  
  <pre><code> Fe.model.fitted &lt;- cbind(data.reg2, resid=resid(FE.model), fitted=fitted(FE.model))
  </code></pre>
  
  <p>However, I get this error with that: </p>
  
  <pre><code> Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ""pseries"" to a data.frame
  </code></pre>
  
  <p>Are there any other ways to get my fitted values in my base dataset? Or can someone explain the error I'm getting and maybe a way to fix it?</p>
  
  <p>I should note that I don't want to manually compute the yhats based on my betas. I have way too many independent variables for that option and my defined formula (fml) may change so that option would not be efficient. </p>
  
  <p>Many thanks!!</p>