[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: RE: How to construct a duration variable?
Thank you all for replying.
The codes I am using to create the duration variable are:
tsset hhid period ;
spell brand ;
bysort _spell: gen duration = _N ;
drop _* ;
It works perfect.
On 4/6/06, Nick Cox <email@example.com> wrote:
> The problem identified by Scott is that
> Brand is a string variable, at least
> as created by him when setting up the
> This would be another way
> tsset hhid Period
> tsspell, fcond(Switch == 1 | L.Period == .)
> bysort hhid _spell : gen duration = _N
> L.Period == . catches the first observation
> in each panel.
> tsspell, fcond(Switch == 1 | _n == 1)
> would also work, but this hinges on knowing
> how -tsspell- does the job.
> Scott Merryman
> > A slight modification is necessary:
> > tsset hhid per
> > encode b, gen(b2)
> > tsspell b2
> > bysort hhid _spell: replace _seq = _seq[_N]
> > rename _seq duration
> > drop _* b2
> > -tsspell- creates _spell by:
> > = by hhid: gen long _spell = sum((brand != L.brand) | (_n ==
> > 1) & __000001)
> > while -spell- uses explicit subscripting.
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
* For searches and help try: