Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

RE: st: How to count switches ?

From   "Martin Weiss" <>
To   <>
Subject   RE: st: How to count switches ?
Date   Sun, 27 Jun 2010 00:38:23 +0200


So -ssc d tsspell- is user-written by Nick Cox.

Try a simple example, and the meaning becomes clear. Everytime your variable changes, _spell is stepped up. So its maximum should be what you want:

set obs 25
set seed 12543
gen byte time=_n
gen byte myvar=runiform()<.7
tsset time
tsspell myvar
l, noo sepby(_spell)
su _spell, mean
di in r "# of spells: " r(max)

BTW, no attachments on Statalist...


-----Original Message-----
From: [] On Behalf Of Ignacio Martinez
Sent: Sonntag, 27. Juni 2010 00:26
Subject: Re: st: How to count switches ?

Thanks a lot for the help. I need a little more help.
I installed tsspell. When I do "tsspell status" it generates 3 new
variables _spell, _seq, _end .
I'm confuse about how can i get the total number of switches in my data
set by using those variables.



On Sat, 2010-06-26 at 15:25 -0400, Dmitriy Krichevskiy wrote:
> There is -tsspell- that does this. (-findit tsspell-).
> On 6/26/10, Ignacio Martinez <> wrote:
> > Hi I'm new in the list and I hope someone can help me.
> >
> > I would like to know how can I count switches in stata. I have the
> > following variables: Year, ID, Employment status
> > I want to generate a variable that ==1 if employment status in year t !=
> > to employment status in year t-1 for each individual.
> >
> > Thanks a lot for the help.
> >
> > -Ignacio
> >

*   For searches and help try:

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