Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Recency Weighted cumulative exposures


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Recency Weighted cumulative exposures
Date   Wed, 13 Nov 2013 17:23:53 -0500

Carmine, no loops are really necessary:

do http://radyakin.org/statalist/2013111301/recencyw.do

Hope this helps, Sergiy Radyakin


On Wed, Nov 13, 2013 at 5:08 PM, Carmine Rossi, Mr
<[email protected]> wrote:
> Dear STATA listers,
>
> I have the following repeated measures data on two subjects with a dose exposure variable. I am interested in creating a variable called “result” that is a recency-weighted cumulative sum.
>
> id   time   dose         result
> 1     1    0              0
> 1     2    0              0
> 1     3    2.6            2.6
> 1     4    2.6            5.174
> 1     5    3.2            8.218
> 2     1    0              0
> 2     2    0              0
> 2     3    0.7            0.7
> 2     4    0.7            1.393
>
> The “result” variable is obtained as a cumulative sum using a weight function:
> Summation of (Dose(i)  x weight(t)), where the weight function is:
>
> W(t) = exp((-(delta time)2)/70.70)
>
> So to get the weighted cumulative sum value of 8.218 (for subject 1 at time 5), rather than 8.4, which would have been the un-weighted cumulative sum, I did the following in a spreadsheet.
>
>
> Id time     dose     delta_t       w(t)      dose(t)*weight(t)        cumulative_sum
> 1   1        0         4           0.80                0                                             0
> 1   2        0         3           0.88                0                                             0
> 1   3       2.6        2           0.94              2.444                                 2.444
> 1   4       2.6        1           0.99              2.574                                 5.018
> 1   5       3.2        0            1                 3.2                                       8.218
>
> Is there a way to do this in STATA with loops? Can anyone provide any suggestions?
>
>
> Carmine Rossi
> PhD Candidate, Epidemiology
> McGill University
> [email protected]
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index