# Re: st: Egen command

 From "Eva Poen" To statalist@hsphsun2.harvard.edu Subject Re: st: Egen command Date Tue, 19 Aug 2008 19:03:53 +0100

The following should do it:

gen first = inrange(visit,2,24)
egen totalcount = total(pillcount) , by(studyid first)

gen pc2_24 = .
replace pc2_24 = (totalcount >=1) if visit==24
pc36_104 = .
replace pc36_104 = (totalcount >=1) if visit==104

Hope this helps,
Eva

> Hi!
> I have cohort dataset monitoring patients' compliance to drugs over 11
> time points (weeks 2, 4, 8, 12, 16, 20, 24, 36, 52, 78 and 104 after
> starting on drugs).
> I want to look at the persistence of their compliance over weeks 2-24
> versus 36-104, i.e. OR of not missing any pill at all over all this
> visits between weeks 2-24 versus 36-104.
>
> At every visit I coded pillcount as 0/1: 1 if patient was not
> compliant versus 0: if patient was compliant.
>
> Now trying to create pc2_24 for weeks 2 to 24, and pc36_104 for week
> 36 to 104 to code them as 0/1 (compliant/not compliant).
>
> I tried
> egen pc2_24=count(pillcount),by(studyid), if visit>0&visit<25
>
> So got
>
> studyid visit   pc2_24
> 1003    2       1
> 1003    4       1
> 1003    8       1
> 1003    12      1
> 1003    16      1
> 1003    20      1
> 1003    24      1
> 1005    2       1
> 1005    4       1
> 1005    8       1
>
>
> But I want the result to look like:
> studyid visit   pc2_24
> 1003    2
> 1003    4
> 1003    8
> 1003    12
> 1003    16
> 1003    20
> 1003    24      1
> 1005    2
> 1005    4
> 1005    8
> 1005    12
> 1005    16
> 1005    20
> 1005    24      1
>
>
> so only to show number 0 or 1 at the last visit, whether visit number
> 24, 20 , or else that is <24
>
>
> Any tips?
>
>
> Thank you and best regards