# AW: st: AW: AW: Automating intervals creation

 From "Martin Weiss" To Subject AW: st: AW: AW: Automating intervals creation Date Tue, 25 Aug 2009 23:33:52 +0200

```<>

******
clear*

inp 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
end

compress
list, noobs

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)

*/ rowtotal(delta1 delta2 /*
*/ delta3 delta4 delta5)

egen last = rowlast(wt??)

*/ if age_ref > weightlst
******

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Thomas Speidel
Gesendet: Dienstag, 25. August 2009 23:26
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: AW: AW: Automating intervals creation

Thanks Martin.
Let's take this obs, for example:

idnum	wt20	wt30	wt40	wt50	wt60	wt70	weight	age_ref	weightlst
721	102	147					180	39	30

Using the suggested approach:

gen weight_decades = abs(wt20 - wt30) + ... + abs(wt60 - wt70)

will generate a missing value. But even if it was to work, for this
specific case I would need to add to it the interval abs(147 - 180) because
age_ref > weightlst.
I hope this makes it clearer.

On Tue, 25 Aug 2009 23:02:04 +0200, "Martin Weiss" <martin.weiss1@gmx.de>
wrote:
>
> <>
>
> I overlooked the missings issue, which -rowtotal- handles more
gracefully,
>
>
>
> " In general, if age_ref > weightlst, I need one more interval computed"
>
>
> What should the additional interval contain?
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
> Gesendet: Dienstag, 25. August 2009 22:45
> An: statalist@hsphsun2.harvard.edu
> Betreff: st: AW: Automating intervals creation
>
>
> <>
>
>
> Your
>
>
> ***
> 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)
> ***
>
>
> could be easily shortened:
>
>
>
> ******
> clear*
> inp x1 x2 x3
> 1 2 3
> 3 2 5
> 5 9 11
> 2 34 90
> 54 32 9
> end
>
> //easy
> gen weight_decades = abs(x1 - x2)+abs(x2-x3)
>
> /difficult
> gen delta1=abs(x1 - x2)
> gen delta2=abs(x2-x3)
>
> //let`s see
> l we*, noo
> ******
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Thomas
Speidel
> Gesendet: Dienstag, 25. August 2009 22:36
> An: statalist@hsphsun2.harvard.edu
> Betreff: st: Automating intervals creation
>
> 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/
>
>
> *
> *   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/
>
>
> *
> *   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/

*
*   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/

*
*   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/
```