I have a dataset of this type:
+---------------------------------------------------------------------------------------------------+
idnum       wt20       wt30       wt40       wt50       wt60   wt70  
weight   age_ref   weightlst 
---------------------------------------------------------------------------------------------------
708   61.23497   61.23497   63.50293   61.23497   86.18255      .       90 
      60         60 
713   56.69905   79.37866   81.64663   104.3262          .      .      100 
      58         50 
721   102.0583   147.4175          .          .          .      .   180.54 
      39         30 
+---------------------------------------------------------------------------------------------------+
where:
wt*: weight captured at different ages (10-yr interval)
weight: weight at reference time
age_ref: age at reference time
weightlst: age at last measurement before reference
I am trying to create a measure of weight fluctuation as follows:
-----------------------------
gen delta1 = abs(wt20 - wt30)
gen delta2 = abs(wt30 - wt40)
gen delta3 = abs(wt40 - wt50)
gen delta4 = abs(wt50 - wt60)
gen delta5 = abs(wt60 - wt70)
egen weight_decades = rowtotal(delta1 delta2 delta3 delta4 delta5)
-----------------------------
I would like to also capture the last interval for some people.  For
example for id==721, I have weight measured at reference (age 39) but the
last recorded weight is at age 30 (wt30).  Thus, the above code will only
compute 1 interval. 
In general, if age_ref > weightlst, I need one more interval computed . 
The preferred way would be to automate my code above to include these
instances. Thanks for any help. 
Thomas Speidel
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/