title: Create a panel data frame
body: <p>I would like to create a panel from a dataset that has one observation for every given time period such that every unit has a new observation for every time period. Using the following example:</p>
  
  <pre><code>id &lt;- seq(1:4)
  year &lt;- c(2005, 2008, 2008, 2007)
  y &lt;- c(1,0,0,1)
  frame &lt;- data.frame(id, year, y)
  frame
  
   id year y
  1  1 2005 1
  2  2 2008 0
  3  3 2008 0
  4  4 2007 1
  </code></pre>
  
  <p>For each unique ID, I would like there to be a unique observation for the year 2005, 2006, 2007, and 2008 (the lower and upper time periods on this frame), and set the outcome y to 0 for all the times in which there isn't an existing observation, such that the new frame looks like:</p>
  
  <pre><code> id year y
  1  1 2005 1
  2  1 2006 0
  3  1 2007 0
  4  1 2008 0
  ....
  13  4 2005 0
  14  4 2006 0
  15  4 2007 1
  16  4 2008 0
  </code></pre>
  
  <p>I haven't had much success with loops; Any and all thoughts would be greatly appreciated.</p>