How to get individual coefficients and residuals in panel data using fixed effects
<p>I have a panel data including income for individuals over years, and I am interested in the income trends of individuals, i.e individual coefficients for income over years, and residuals for each individual for each year (the unexpected changes in income according to my model). However, I have a lot of observations with missing income data at least for one or more years, so with a linear regression I lose the majority of my observations. The data structure is like this:</p>
<pre><code>caseid&lt;-c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4)
years&lt;-c(1998,2000,2002,2004,2006,2008,1998,2000,2002,2004,2006,2008,
1998,2000,2002,2004,2006,2008,1998,2000,2002,2004,2006,2008)
income&lt;-c(1100,NA,NA,NA,NA,1300,1500,1900,2000,NA,2200,NA, 
NA,NA,NA,NA,NA,NA, 2300,2500,2000,1800,NA, 1900)
df&lt;-data.frame(caseid, years, income)
</code></pre>
<p>I decided using a random effects model, that I think will still predict income for missing years by using a maximum likelihood approach. However, since Hausman Test gives a significant result I decided to use a fixed effects model. And I ran the code below, using plm package:</p>
<pre><code>inc.fe&lt;-plm(income~years, data=df, model=&quot;within&quot;, effect=&quot;individual&quot;)
</code></pre>
<p>However, I get coefficients only for years and not for individuals; and I cannot get residuals.
To maybe give an idea, the code in Stata should be</p>
<pre><code> xtest caseid
 xtest income year
 predict resid, resid
</code></pre>
<p>Then I tried to run the pvcm function from the same library, which is a function for variable coefficients.</p>
<pre><code>inc.wi&lt;-pvcm(Income~Year, data=ldf, model=&quot;within&quot;, effect=&quot;individual&quot;)
</code></pre>
<p>However, I get the following error message:</p>
<pre><code> &quot;Error in FUN(X[[i]], ...) : insufficient number of observations&quot;.
</code></pre>
<p>How can I get individual coefficients and residuals with pvcm by resolving this error or by using some other function?</p>
<p>My original long form data has 202976 observations and 15 years.</p>