Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: Automating intervals creation


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Automating intervals creation
Date   Tue, 25 Aug 2009 22:44:36 +0200

<>


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)
egen weight_decades2 =rowtotal(delta1 delta2)

//let`s see
compare weight_decades weight_decades2
l we*, noo
******


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Thomas Speidel
Gesendet: Dienstag, 25. August 2009 22:36
An: [email protected]
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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index