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: Multiple record per individual data: Counting frequency in which an individual changes from one variable value to another


From   Nick Cox <[email protected]>
To   [email protected]
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 <[email protected]> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index