title: Lag unbalanced panel dataset in Matlab
body: <p>I have an unbalanced panel dataset in Matlab that I need to lag. Unbalanced panel datasets are quite easu to work with in R with the <code>plm</code> package. Is there a similar functionality in Matlab? Here is a toy example:</p>
  
  <pre><code>A = table(sort([repmat([1;2],4,1);repmat(3,3,1)]),[repmat((1994:1997).',2,1);(1995:1997).'],normrnd(100,1,11,1))
  
  A = 
  
      Var1    Var2     Var3 
      ____    ____    ______
  
      1       1994    98.423
      1       1995    100.51
      1       1996    100.28
      1       1997    100.03
      2       1994    98.666
      2       1995    101.13
      2       1996    100.35
      2       1997    99.701
      3       1995    100.02
      3       1996    99.738
      3       1997     98.25
  </code></pre>
  
  <p>For each instance of Var1, I would like to lag the value of Var3 one year. Note that there is no value for 1994 for Var1=3. Thus, I would like the following: </p>
  
  <pre><code>    Var1    Var2     Var3      Var4 
      ____    ____    ______    ______
  
      1       1994    98.423       NaN
      1       1995    100.51    98.423
      1       1996    100.28    100.51
      1       1997    100.03    100.28
      2       1994    98.666       NaN
      2       1995    101.13    98.666
      2       1996    100.35    101.13
      2       1997    99.701    100.35
      3       1995    100.02       NaN
      3       1996    99.738    100.02
      3       1997     98.25    99.738
  </code></pre>
  
  <p>Is there an easy way to do this in Matlab?</p>