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: highest date in repeated data


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: highest date in repeated data
Date   Wed, 6 Feb 2013 14:34:15 +0000

That should work, but it is probably better style, at least for
related problems, to work with -by:-.

bysort child (month) : gen exit = intervdate[_N]

Another way to do it offers some protection against missing values

egen exit = max(intervdate), by(child)

But note also that this has been an FAQ since 2002:

FAQ     . . . . . . . . . . . . . . . . . . . . . . . Generating the last date
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
 How can I generate a variable containing the last of  several dates?

http://www.stata.com/support/faqs/data-management/generating-last-date/

Nick

On Wed, Feb 6, 2013 at 2:04 PM, Jan Ditzen <[email protected]> wrote:

> a very simple approach:
>
> sort child month
> gen exit = intervdate if child != child[_n+1]
>
> I am sure that there is an alternative approach, but this one should work.

Dherani, Mukesh:

>> I have panel data in which a child is observed repeatedly at an interval
>> of 6 months at 0,6,12 and 18months. However, some children dropped out at 6
>> or 12 months.  I want to create a date of exit for them which should be the
>> latest date,  say date of interview on visit at 12 month if 18 month visit
>> did not happen. For example for child 1 below it should be 1/1/2010 and only
>> appear in that row.  I am doing this to carry out 'stset' commands.
>>
>> child   intervdate      month   exit
>> 1       01/01/2010      0
>> 1       01/07/2010      6
>> 1       01/01/2011      12
>> 2       01/02/2010      0
>> 2       01/07/2010      6
>> 2       01/02/2011      12
>> 2       01/07/2011      18      01/07/2011
>> 3       01/01/2010      0
>> 3       01/07/2010      6
>>
>>
>> How can I copy latest date is not clear.
>> I tried
>>
>> replace exit= interdate if month==18
>> replace exit= interdate if month==12 & missing(interdate)
>>                 // problem with this is for child 2 it is showing
>> exit=1/2/2011 and final record is excluded
>>
>> Your help is appreciated (I am using stata 10). Than you in advance.
*
*   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