title: Panel regression in R with variable coefficients
body: <p>We have tried to do two (similar) panel regressions in R. </p>
  
  <p>1) One with time and individual fixed effects (the usual intercept dummies) using plm(). However, we are only interested mostly interested in a "slope coefficient" or beta for each individual and not one for all of the individuals:</p>
  
  <p><a href="https://i.stack.imgur.com/9iwBV.png" rel="nofollow noreferrer">Regression 1</a></p>
  
  <p>Where alpha_i is the individual fixed effect, gamme_t is the time fixed effect. The sum of X is the variable X and three lags:</p>
  
  <p><a href="https://i.stack.imgur.com/G7ASv.png" rel="nofollow noreferrer">Sum X variable</a></p>
  
  <p>We have already included the lagged X variables as new columns in our dataset so in our specification in the code we simply treat them as four different variables:
  This is an attempt at using plm() and include our own dummy variables for each individual Beta</p>
  
  <pre><code>plm(income ~ (factor(firmid)-1)*(expense_rate + lag1 + lag2 + lag3), data = data1,
  effect = c("time"), model = c("within"), index = c("name", "date"))
  </code></pre>
  
  <p>The lag1, lag,2, lag2 are the lagged variables of expense rate.
  Data1 is in the form of a data frame.
  “(factor(firmid)-1)” is an attempt at introducing dummies to get Betas for each individual instead of one for all individuals.</p>
  
  <p>2) The second (and simpler) regression is:
  <a href="https://i.stack.imgur.com/fXZfy.png" rel="nofollow noreferrer">Regression 2</a></p>
  
  <p>This is an example of our attempt at using pvcm</p>
  
  <pre><code>pvcm1 &lt;- pvcm(income ~ expense_rate + lag1 + lag2 + lag3, data = data1,
            effect = "individual", model = "within")
  </code></pre>
  
  <p>Our question is what specific code and or packages/functions which would be suitable for these regressions. We have tried pvcm to no avail, running into errors such as:
  “Error in table(index[<a href="https://i.stack.imgur.com/9iwBV.png" rel="nofollow noreferrer">1</a>], index[<a href="https://i.stack.imgur.com/G7ASv.png" rel="nofollow noreferrer">2</a>], useNA = "ifany") : 
    attempt to make a table with >= 2^31 elements”
  and
  “Error: cannot allocate vector of size 599.7 Gb”</p>
  
  <p>. Furthermore, pvcm() does not seem to be able to cope with both individua and time fixed effects as in 1). </p>