I have data that look like the following:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(sid startyr endyr cost)
1001 2006 9999 545
1001 2010 2011 690
1001 2011 2012 701
end
I would like to expand the first row where the start year is 2006. The end year 9999 represents whatever is the year before the following row, so in this case 2009 (because the following row is 2010). I would also like the rows that I expand to have a start year that is the year following the previous row. For example, I am looking for something like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(sid startyr endyr cost)
1001 2006 2007 545
1001 2007 2008 545
1001 2008 2009 545
1001 2009 2010 545
1001 2010 2011 690
1001 2011 2012 701
end
Any suggestions greatly appreciated.