Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: need little help


From   Ulrich Kohler <kohler@wz-berlin.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: need little help
Date   Wed, 23 Apr 2003 13:44:06 +0200

Giulio Rizzoli wrote:
> I have several records per id: At subsequent times my patient
> have received the medication amed or bmed
> In the last record within id I woul'd like to generate
> a variable abmed wich will be 1 (or some value x) only if the  patient
> has in the prior records experinced the use of both amed and bmed or will
> be 0 otherwise.
>
> id time amed bmed abmed
> 10  81  1	  0     .
> 10  87  0	  1     .
> 10  83  0	  1     1
> 11  70  0	  1     .
> 11  76  0	  1	  .
> 11  84  1	  0     .
> 11  99  1	  0     1
> 12  88  1     0	  .
> 12  98  1	  0     0

by id, sort: gen amedx = sum(amed)
by id: gen bmedx = sum(bmed)
by id: gen abmed = amedx[_N]>=1 & bmedx[_N]>=1 & _n==_N
drop amedx bmedx


-- 
kohler@wz-berlin.de


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index