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: Carry forward an observation within a time frame


From   Robert Picard <picard@netbox.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Carry forward an observation within a time frame
Date   Wed, 9 Oct 2013 11:36:23 -0400

Sorry, just noticed that I accidentally hit a key just before copying
the code, the before last line should read:

by patid arun: gen CD4_cf = CD4[1] if edate-edate[1] < 120

Robert

On Wed, Oct 9, 2013 at 11:22 AM, Robert Picard <picard@netbox.com> wrote:
> I think the following will work for you.
>
> Robert
>
> * ------------------ begin example --------------
> clear
> input patid str20 sdate CD4
> 1007 "5-May-55" .
> 1007 "1-Jan-00" .
> 1007 "3-Apr-02" 5
> 1007 "8-Apr-02" .
> 1007 "11-Apr-02" .
> 1007 "13-May-02" .
> 1007 "14-May-02" 4
> 1007 "17-Jun-02" 9
> 1007 "12-Nov-02" .
> 1007 "27-Jan-03" 6
> 1007 "17-Mar-03" .
> 1007 "14-Apr-03" 0
> 1007 "30-May-02" .
> 1007 "30 Jun-02" .
> 1007 "30-Jul-02" .
> 1007 "30-Aug-02" .
> 1008 "27-Jan-03" 6
> 1008 "17-Mar-03" .
> end
>
> gen obs = _n
> gen edate = date(sdate,"DMY",2019)
> format %d edate
> list
>
> * if there are more than one obs per date, put
> * obs with a non-missing CD4 code last
> gen isgood = !mi(CD4)
> sort patid edate isgood CD4 obs
>
> * each valid code starts a new run
> by patid: gen arun = sum(isgood)
>
> * carry forward the valid code within a run
> sort patid arun edate isgood CD4 obs
> by patid arun: gen CD4_cf = CD4[1] if edate-edate[1] < 120x
> list, noobs sepby(patid arun)
> * ------------------ end example ----------------
>
> On Wed, Oct 9, 2013 at 10:45 AM, Benigno Rodriguez, MD
> <benignor@gmail.com> wrote:
>> Dear David:
>>
>> Thank you for this detailed response. But my problem is that I need to carry
>> forward to a given row with a missing CD4 the closest in time CD4 value, as
>> long as it is within the previous 4 months (the last 120 days is enough
>> precision for my purposes).
>>
>> Correct me if I'm thinking about this wrong, but with your approach, a value
>> could be propagated down even if the "seed" for that value occurred more
>> than 4 months earlier. I have added a few rows (artificially) to illustrate.
>> Look at row 10. It occurs within 4 month of row[_n-1], but I don't want it
>> filled out with that value, because the last time we actually had a
>> non-missing value was in row 3, which is more than 4 months prior to row 10.
>>
>> The approach I was trying was to try to define a "spell" as one that begins
>> with a missing CD4 AND for which the row above has a non-missing value
>> (easily done). But implementing the solution from there has proven
>> challenging.
>>
>>
>>         patid   date            CD4     desired
>> 1.      1007    5-May-55        .       .
>> 2.      1007    1-Jan-00        .       .
>> 3.      1007    3-Apr-02        5       5
>> 4.      1007    8-Apr-02        .       5
>> 5.      1007    11-Apr-02       .       5
>> 6.      1007    13-May-02       .       5
>> 7.      1007    30-May-02       .       5
>> 8.      1007    30 Jun-02       .       5
>> 9.      1007    30-Jul-02       .       5
>> 10.     1007    30-Aug-02       .       .
>>
>>
>> BENIGNO RODRIGUEZ G., MD, MSc, FIDSA
>> Associate Professor of Medicine
>> Division of Infectious Diseases and HIV Medicine
>> Case Western Reserve University
>> Ph: +1-216-844-2057
>> Fax: +1-216-8445523
>> *
>> *   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