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   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: How to construct a duration variable?
Date   Thu, 6 Apr 2006 13:43:51 -0500

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


Scott



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