Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Analysing longitudinal data |
Date | Tue, 26 Feb 2013 15:39:33 +0000 |
I don't think any programming is needed here at all, just a few commands issued in a do-file or interactively. Your first two questions are of the form {count|average} in moving time interval and both are addressed in moderate detail within SJ-7-3 pr0033 . . . . . . . . . . . . . . Stata tip 51: Events in intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q3/07 SJ 7(3):440--443 (no commands) tip for counting or summarizing irregularly spaced events in intervals http://www.stata-journal.com/sjpdf.html?articlenum=pr0033 The last has been discussed in various places, but rather than references here is some sample code. gen NotWanted = (value < 1) | missing(value) bysort ID (NotWanted Date) : gen TimeSinceLast = Date - Date[_n-1] if !NotWanted The logic looks a little contrived, but the idea is to get a sort order that looks like this, so that the time since the last previous event is just the current date minus the previous date. For individual, there will be only one such date, 30/04/2011, for which the answer will be 2 days. The answer for the first will be missing. 1 1.5 28/04/2011 1 1.3 30/04/2011 1 0.6 02/03/2010 1 0.6 24/05/2010 1 0.6 16/08/2010 1 0.6 10/11/2010 1 0.9 09/02/2011 1 0.7 01/05/2011 1 0.6 03/05/2011 1 0.6 09/05/2011 Once you have values in a variable, -summarize- gives you the mean. Nick On Tue, Feb 26, 2013 at 3:18 PM, K Jensen <k.x.jensen@gmail.com> wrote: > I have a dataset that looks like the sample I have pasted in at the > end of this message, with repeated measures over time on the same > individuals. > > I would like to answer questions like: > When a value was over 1, how many were measured again within the next > week? How many of those were also over 1? > What was the average interval between a value being over 1 and the > next value for that individual? > > How would I go about programming this in Stata? > > Thankyou > > Karin > > ID Value Date > 1 0.6 02/03/2010 > 1 0.6 24/05/2010 > 1 0.6 16/08/2010 > 1 0.6 10/11/2010 > 1 0.9 09/02/2011 > 1 0.7 01/05/2011 > 1 1.5 28/04/2011 > 1 1.3 30/04/2011 > 1 0.6 03/05/2011 > 1 0.6 09/05/2011 > 2 0.6 14/04/2009 > 2 0.7 23/07/2009 > 2 0.6 16/11/2009 > 2 0.6 29/12/2009 > 2 0.6 30/03/2010 > 2 0.9 01/07/2010 > 2 1.2 27/09/2010 > 2 0.7 12/10/2010 > 2 0.7 26/10/2010 > 2 0.8 25/03/2011 > 3 0.3 21/01/2009 > 3 0.3 05/11/2009 > 3 0.1 01/03/2010 > 3 0.2 24/05/2010 > 3 0.2 18/08/2010 > 4 0.9 16/02/2010 > 4 1.0 01/03/2010 > 4 0.9 12/03/2010 > 4 1.1 25/03/2010 > 4 0.5 01/06/2010 > 4 0.4 31/08/2010 > 4 0.6 30/11/2010 > 4 0.6 19/04/2011 * * 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/