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: Carrying forward last value conditioned on time since last non-missing value- panel data


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Carrying forward last value conditioned on time since last non-missing value- panel data
Date   Wed, 28 Aug 2013 09:21:55 +0100

by id: replace prevmeas = glucose[_n-1] if missing(glucose)

should be

by id: replace prevmeas = prevmeas[_n-1] if missing(glucose)
Nick
[email protected]


On 28 August 2013 08:51, Nick Cox <[email protected]> wrote:
> I assume -testdate- is a daily date variable formatted %td or %d.
>
> What was the previous date measured?
>
> clonevar prevdate = testdate if !missing(glucose)
> bysort id (testdate) : replace prevdate = prevdate[_n-1] if missing(glucose)
>
> What was the previous value measured?
>
> clonevar prevmeas  = glucose if !missing(glucose)
> by id: replace prevmeas = glucose[_n-1] if missing(glucose)
>
> This is an FAQ! See
> http://www.stata.com/support/faqs/data-management/replacing-missing-values/
> but note the warning there on interpolation.
>
> Replace missings if within one year
>
> clonevar glucose2 = glucose
> replace glucose2 = prevmeas if missing(glucose)
>                         & inrange(testdate, prevdate, prevdate + 365)
>
> The last two lines are one command.
>
> But all that said, this seems an arbitrary procedure. Suppose a year
> and a day elapses between measurements. Do you still want to use the
> previous value a year ago, not the next?
>
> For interpolation solutions, see
>
> -ipolate- (official)
> -cipolate- (SSC)
> -csipolate- (SSC)
> -pchipolate- (SSC)
> -nnipolate- (SSC)
>
> Nick
> [email protected]
>
>
> On 28 August 2013 07:03, Amit Achhra <[email protected]> wrote:
>
>> I was wondering if anyone could help me in this. I have panel data of the form:
>>
>> id              testdate        glucose         Desired output for glucose
>> 1               23-Apr-09       5.9             5.9
>> 1               24-Jun-09       .               5.9
>> 1               23-Jul-09       6.7             6.7
>> 1               24-Aug-09       .               6.7
>> 1               6-Nov-09        .               6.7
>> 1               22-Jan-10       .               6.7
>> 1               22-Apr-10       5.8             5.8.
>> 1               24-May-11       .               .
>> 1               3-Aug-11        6.4             6.4
>> 1               28-Dec-11       .               6.4
>> 1               12-Sep-12       .               .
>>
>>
>> To fill in missing values of the variable glucose, I would like to carry last non-missing value forward but only for one year ahead (i.e. only for 1 year from the last non-missing value) (see 'desired output').
>> This is because I'm assuming that glucose will not have an impact on my outcome if it was measured more than a year ago.
*
*   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