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
Amit Achhra <[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 23:29:34 +0000
Dear Nick
Thank you so much.
Yes it is an arbitrary decision taken by the writing group- mainly to do sensitivity analyses. Luckily most people in our dataset had 6-8 monthly lab values measured.
Thanks again
Amit
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Wednesday, 28 August 2013 6:22 PM
To: [email protected]
Subject: Re: st: Carrying forward last value conditioned on time since last non-missing value- panel data
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-va
> lues/ 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/
*
* 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/