Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: How to construct a duration variable?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: How to construct a duration variable?
Date   Thu, 6 Apr 2006 21:00:15 +0100

I think Richard disagrees slightly, but -spell-, whiIe
it is still there on SSC for users of Stata 6, has not
been touched by either of us since 2000. 

I'd recommend instead -tsspell-, 
which is the successor maintained by me (with 
ack'ts to Richard for his contributions). -tsspell- 
is slightly more restrictive in insisting on -tsset-, 
but in practice that limitation is no limitation. 
It too is present on SSC. 

Nick 
[email protected] 

Scott Merryman
 
> Here is one way.  It makes use of Nick Cox and Richard 
> Goldstein's -spell-.
> 
> clear
> input hhid    period  str1 brand    switch  Duration
> 1         1         A           0           1
> 1         2         B           1           4
> 1         3         B           0           4
> 1         4         B           0           4
> 1         5         B           0           4
> 1         6         C           1           2
> 1         7         C           0           2
> 1         8         A           1           1
> 1         9         B           1           4
> 1        10         B           0           4
> 1        11         B           0           4
> 1        12         B           0           4
> 1        13         C           1           2
> 1        14         C           0           2
> end
> 
> tsset hhid per
> spell b
> bysort hhid _spell: replace _seq = _seq[_N]
> rename _seq duration
> drop _* 
> l
 

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index