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   "paul o'brien" <paul.obrien@afe2.org.uk>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Identifying visits with 1 time period of an event
Date   Tue, 18 Feb 2014 18:39:52 +0000

Thanks Nick,

I think I have not been clear enough. I have the first 3 variable, and
want to create the two on the right, follow-up and follow-up within 1
time period.

The key thing is how to mark visits that follow the procedure. So I
need to create a variable followup with the value 1 for the first
observation/visit after the procedure. With that I can use your
suggestion to identify the follow-up visits within 1 time period after
the procedure.

Thanks,

Paul

On 17 February 2014 23:33, Nick Cox <njcoxstata@gmail.com> 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
> njcoxstata@gmail.com
>
> On 17 February 2014 20:23, Paul O'Brien <paul.obrien@afe2.org.uk> 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/



-- 
Dr Paul O'Brien
Raymede Clinic
Westside Contraception and Sexual Health Services
Central London Community Healthcare
Exmoor St
London
W10 6DZ
UK
+44 (0)20 8962 5511
*
*   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