title: Panel data: dealing with lagging and binary dependent variable with plm
body: <p>I am attempting to run a pooled logistic regression with panel data and a binary dependent variable.  Since I wanted to lag some of the variables, I used the plm package to create them.  When I tried to do it other  ways, I ran into problems.  I can't use lag or embed, because it is panel data.</p>
  <pre><code>hybridsubsidies &lt;-pdata.frame(reduced, c(&quot;state&quot;,&quot;year&quot;))
  
  lagee&lt;-(lag(hybridsubsidies$eespending,1))
  lagratio&lt;-(lag(hybridsubsidies$ratio, 1))
  laggopvote&lt;-(lag(hybridsubsidies$gopvote, 1))
  laggasoline&lt;-(lag(hybridsubsidies$gasoline, 1))
  </code></pre>
  <p>I wanted to put all the variables into the original data frame (hybridsubsidies) before I ran the pooled analysis.  I'm pretty sure I don't need to, but I'm a visual person, and would like to verify the format of the data is appropriate before running any analysis.</p>
  <p>From the output below, it looks like everything is done correctly.</p>
  <blockquote>
  <p>head(lag(hybridsubsidies$eespending,1))</p>
  <p>ALABAMA-1999 ALABAMA-2000 ALABAMA-2001 ALABAMA-2002 ALABAMA-2003 ALABAMA-2004</p>
  <pre><code>     NA        58294        55378        26982        28264         2566 
  </code></pre>
  <p>head(hybridsubsidies$eespending)</p>
  <p>ALABAMA-1999 ALABAMA-2000 ALABAMA-2001 ALABAMA-2002 ALABAMA-2003 ALABAMA-2004</p>
  <pre><code>  58294        55378        26982        28264         2566        26906 
  </code></pre>
  </blockquote>
  <p>My problem is that when I try and assign this lag variable as a vector in the data frame, this way,</p>
  <pre><code>hybridsubsidies$lagee&lt;-(lag(hybridsubsidies$eespending,1))
  </code></pre>
  <p>it does so(when I call the names in the dataframe, they are included), but then I can no longer view the dataframe.  R says to me:</p>
  <blockquote>
  <p>Error in edit.data.frame(get(subx, envir = parent), title = subx, ...) :
  can only handle vector and factor elements</p>
  </blockquote>
  <p>How can I solve this so that I can view the data frame before I run the analysis?  I want to look at it, since it looks like I will have to use glm instead of plm (pooling)  for this analysis since the dependent variable is a binary variable and plm does not support these d.v.'s</p>
  <p>This has been giving me problems for awhile now.</p>
  <blockquote>
  <p>col1   ST   YR   EELAG  EE</p>
  <p>[1,]    1      1       NA    58294</p>
  <p>[2,]    1    2  58294  55378</p>
  <p>[3,]    1    3  55378  26982</p>
  <p>[4,]    1    4  26982  28264</p>
  <p>[5,]    1    5  28264   2566</p>
  <p>[6,]    1    6   2566  26906</p>
  <p>[7,]    1    7  26906  29466</p>
  <p>[8,]    2    1     NA    355</p>
  <p>[9,]    2    2    355    259</p>
  <p>[10,]    2    3    259    224</p>
  <p>[11,]    2    4    224    217</p>
  <p>[12,]    2    5    217    241</p>
  <p>[13,]    2    6    241    231</p>
  <p>[14,]    2    7    231    231</p>
  <p>[15,]    3    1     NA   5111</p>
  <p>[16,]    3    2   5111   3753</p>
  <p>[17,]    3    3   3753   2211</p>
  <p>[18,]    3    4   2211   1452</p>
  <p>[19,]    3    5   1452   2913</p>
  <p>[20,]    3    6   2913   3128</p>
  <p>[21,]    3    7   3128   7132</p>
  <p>[22,]    4    1     NA   1597</p>
  <p>[23,]    4    2   1597    905</p>
  </blockquote>