Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Multiple record per individual data: Counting frequency in which an individual changes from one variable value to another


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Multiple record per individual data: Counting frequency in which an individual changes from one variable value to another
Date   Sat, 6 Aug 2011 09:21:54 +0100

bysort study_id : gen different = sum(X != X[_n-1]) & _n > 1)
by study_id : replace different = different[_N]

See -tsspell- from SSC and

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/07   SJ 7(2):249--265                                 (no commands)
        shows how to handle spells with complete control over
        spell specification


Nick

On Fri, Aug 5, 2011 at 10:04 PM, Weichle, Thomas <Thomas.Weichle@va.gov> wrote:

> I have data which contains multiple records per individual.  I have a
> categorical variable X (values 1,2,3) which can vary from record to
> record within the individual.  I'd like to know if there is a command
> that will count the number of times in which an individual changes to a
> different value in variable X.  Consider the following example:
>
> study_id        X
> 100             2
> 100             2
> 100             2
> 100             3
> 555             1
> 555             1
> 555             2
> 555             2
> 555             1
> 555             1
>
> study_id 100 would count as 1 change.
> study_id 555 would count as 2 changes.

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index