title: replace missing value based on linear prediction of nearby cells
body: <p>I have a dataset (<code>tsset</code>) that has observations in some years but not others:</p>
  
  <pre><code>year x
  1990 600
  1991 .
  1992 .
  1993 .
  1994 .
  1995 1100
  1996 .
  1997 .
  1998 1700
  </code></pre>
  
  <p>Suppose I am willing to make the assumption that every missing observation between two non-missing years (say 1990 and 1995 for example) can be imputed by a linear prediction between the said non-missing years, which makes the data like</p>
  
  <pre><code>year  x
  1990  600
  1991 [700]
  1992 [800]
  1993 [900]
  1994 [1000]
  1995  1100
  1996 [1300]
  1997 [1500]
  1998  1700
  </code></pre>
  
  <p>Is there anyway to do this efficiently? I am currently using something like <code>cond(year&gt;1990 &amp; year &lt;1995, [Value if True], [Value if False])</code>, but I do not know a good way to for all years from 1991 to 1994 to find 1990 as their lower bound and 1995 as the upper bound.</p>
  
  <p>Stata's <a href="http://www.stata.com/support/faqs/data-management/replacing-missing-values/" rel="nofollow">documentation</a> demonstrates the technique of using <code>x[_n-1]</code> if I simply want to fill missing values from the previous cell, but not sure how this can be extended to solve my problem as described above. </p>