title: How do I "fill down" a dataset in Stata, but for only a certain number of rows?
body: <p>I have a dataset with observations at specific timepoints, but those timepoints (and the length of time between them) vary by group.  I'm trying to "fill down" the data so that existing observations are carried down into missing cells.  But I only want to do this for a certain number of rows after the original observation.  So for example, I could have a dataset that looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/uhe6C.png" alt="enter image description here"></p>
  
  <p>For group A, I'd want to fill in the value for 2002 with 2001's value, 2004 with 2003, etc.  I wouldn't want to fill in 2000 at all, since I don't have the preceding value.  And I ALSO wouldn't want to fill in the 2011 value, because the "cyclelength" variable tells me that group A's observations are supposed to take place every two years, so I don't want to carry data forward past that.  2011 is just a genuinely missing value.</p>
  
  <p>Similarly, in group B, I'd want to carry 2000's value forward into years 2001, 2002, and 2003 (because the "cyclelength" here is 4 years).  I'd want to carry 2004's value into 2005, 2006, and 2007, but not beyond that--the later years should stay missing.</p>
  
  <p>I've tried setting this up with the "carryforward" command, but haven't figured out how to have it stop filling down after a specified number of years that varies by group.  Is there a way to do this, either with carryforward or otherwise?</p>