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: collapsing data from multiple follow-up visits


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: collapsing data from multiple follow-up visits
Date   Wed, 2 Mar 2011 09:05:23 +0000 (GMT)

--- On Tue, 1/3/11, Ashwin Ananthakrishnan wrote:
> Each participate has one row with their baseline 
> information (medications). At each subsequent visit, the
> medication information is updated. This is on separate row.
> What I would like to do to facilitate analysis is to
> collapse all data for each participant into one row. All I'm
> interested in knowing if if they were ever on a specific
> medication during their follow-up.

What about this?

*-------------- begin example -----------------
// create some example data
drop _all
input id visit med 
      1  1     1
      1  2     0
      1  3     3
      2  1     1
      2  2     1
      3  1     2 
      3  2     2 
      3  3     3
      3  4     3
end

// did person i at visit t get medication 3?
gen med3 = med == 3 if !missing(med)

// how many times did person i get medication 3?
bys id : egen Nmed3 = total(med3)

// did person i ever get medication 3?
replace med3 = Nmed3 > 0 if !missing(Nmed3)

// Nmed3 is no longer needed
drop Nmed3

// keep for each person the first visit
bys id (visit) : keep if _n == 1

// see the result
list
*------------------- end example --------------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index