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: Identifying visits with 1 time period of an event


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Identifying visits with 1 time period of an event
Date   Tue, 18 Feb 2014 00:29:31 +0000

Indicator variables follow from e.g.

(time2 == time) & (time2 - time1) <= 1

Subscript technique also leads to

bysort id (time) : gen within1 = procedure[_n-1] & (followup==1) &
((time - time[_n-1]) <= 1)

The technique I showed earlier appears to have many applications and
is not limited to comparison with the immediately previous
observation.

Nick
[email protected]


On 17 February 2014 23:33, Nick Cox <[email protected]> wrote:
> The first time when something happened is one and the same as the
> minimum time. For panel data, -egen-'s -min()- function serves fine to
> identify such times separately by panels.
>
> Here "something" means either -procedure == 1- or -followup == 1- so
> specifying either condition can be done by instructing Stata to ignore
> anything else. -min()- takes expressions, so that can be made explicit
>
> egen time1 = min( cond(procedure == 1, time, .) ) , by(id)
> egen time2 = min( cond(followup == 1, time, .) ), by(id)
>
> This is equivalent and according to taste cunning or cryptic:
>
> egen time1 = min(time/procedure), by(id)
> egen time2 = min(time/(followup == 1)), by(id)
>
> Now we are on the home straight and contemplating reward:
>
> gen lag = time2 - time1
>
> gen within1 = (time2 - time1) <= 1
>
> For a self-indulgent exploration of similar trickery, see
>
> http://www.stata-journal.com/article.html?article=dm0055
>
> More concise statements are likely to be possible, but may defy
> simultaneous maintenance of sanity and balancing of parentheses.
>
> Nick
> [email protected]
>
> On 17 February 2014 20:23, Paul O'Brien <[email protected]> wrote:
>
>> I have longitudinal data on visits to a clinic during which a procedure sometimes occurs.
>>
>> I want to mark follow-up visits if the procedure occurred and mark the visits within 1 time period of the procedure, as in the last two variables here.
>>
>> clear
>> input ///
>> id           time      procedure      followup      followup1
>> 1                1             0             0             0
>> 1                2             1             0             0
>> 1                3             0             1             1
>> 1                4             0             2             0
>> 1                5             0             3             0
>> 2                3             1             0             0
>> 2                4             0             1             1
>> 2                5             0             2             0
>> 2                7             0             3             0
>> 2                8             0             4             0
>> 2                10            0             5             0
>> 3                1             0             0             0
>> 3                2             0             0             0
>> 3                3             0             0             0
>> 3                4             0             0             0
>> 4                2             0             0             0
>> 4                3             1             0             0
>> 4                6             0             1             0
>> 4                7             0             2             0
>> end
>>
>> I have struggled with _n and _N but cannot get the follow to start after the event.
*
*   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