[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: RE: How to construct a duration variable?
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.
> 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: