Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: capturing the sizes of the sequences of countinous (uninterrupted) values equal to 1
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: capturing the sizes of the sequences of countinous (uninterrupted) values equal to 1
Date
Thu, 1 Dec 2011 11:54:44 +0000
egen newid = group(lender borrower), label
tsset newid time
Nick
[email protected]
massimiliano stacchini
Thanks a lot,
If I run the codes that you suggeted me the result is ok.
tsset id time
tsspell, cond(state==1)
Now I just have a slight complication.
My ID is actually composed by a couple of indicators, contained in two separate colums (i.e., ID for lender and ID for borrower).
On the contrary, the tsset command does not allow multiple variable for ID.
Question: how could I get a SINGLE index representing the SPECIFIC COUPLE of indicators.
Thanks in advance.
--- Mer 30/11/11, Nick Cox <[email protected]> ha scritto:
> Toy example using -tsspell- (SSC). What you want is I think
> created
> here as _seq, except that you need to subtract 1.
>
> clear
> set obs 10
> gen id = _n
> forval j = 1/5 {
> gen time`j' = runiform() <
> 0.7
> }
>
> reshape long time , i(id)
> rename time state
> rename _j time
> tsset id time
> tsspell, cond(state==1)
>
> . l
>
> +------------------------------------------+
> | id time state _seq _spell _end |
> |------------------------------------------|
> 1. | 1 1 1 1 1
> 0 |
> 2. | 1 2 1 2 1
> 0 |
> 3. | 1 3 1 3 1
> 1 |
> 4. | 1 4 0 0 0
> 0 |
> 5. | 1 5 0 0 0
> 0 |
> |------------------------------------------|
> 6. | 2 1 1 1 1
> 0 |
> 7. | 2 2 1 2 1
> 0 |
> 8. | 2 3 1 3 1
> 0 |
> 9. | 2 4 1 4 1
> 0 |
> 10. | 2 5 1 5 1
> 1 |
> |------------------------------------------|
> 11. | 3 1 1 1 1
> 0 |
> 12. | 3 2 1 2 1
> 0 |
> 13. | 3 3 1 3 1
> 0 |
> 14. | 3 4 1 4 1
> 0 |
> 15. | 3 5 1 5 1
> 1 |
> |------------------------------------------|
> 16. | 4 1 1 1 1
> 1 |
> 17. | 4 2 0 0 0
> 0 |
> 18. | 4 3 0 0 0
> 0 |
> 19. | 4 4 1 1 2
> 0 |
> 20. | 4 5 1 2 2
> 1 |
> |------------------------------------------|
> 21. | 5 1 1 1 1
> 0 |
> 22. | 5 2 1 2 1
> 1 |
> 23. | 5 3 0 0 0
> 0 |
> 24. | 5 4 1 1 2
> 1 |
> 25. | 5 5 0 0 0
> 0 |
> |------------------------------------------|
> 26. | 6 1 1 1 1
> 1 |
> 27. | 6 2 0 0 0
> 0 |
> 28. | 6 3 1 1 2
> 0 |
> 29. | 6 4 1 2 2
> 0 |
> 30. | 6 5 1 3 2
> 1 |
> |------------------------------------------|
> 31. | 7 1 1 1 1
> 0 |
> 32. | 7 2 1 2 1
> 0 |
> 33. | 7 3 1 3 1
> 1 |
> 34. | 7 4 0 0 0
> 0 |
> 35. | 7 5 1 1 2
> 1 |
> |------------------------------------------|
> 36. | 8 1 1 1 1
> 0 |
> 37. | 8 2 1 2 1
> 1 |
> 38. | 8 3 0 0 0
> 0 |
> 39. | 8 4 1 1 2
> 1 |
> 40. | 8 5 0 0 0
> 0 |
> |------------------------------------------|
> 41. | 9 1 1 1 1
> 0 |
> 42. | 9 2 1 2 1
> 0 |
> 43. | 9 3 1 3 1
> 0 |
> 44. | 9 4 1 4 1
> 0 |
> 45. | 9 5 1 5 1
> 1 |
> |------------------------------------------|
> 46. | 10 1 0 0 0
> 0 |
> 47. | 10 2 0 0 0
> 0 |
> 48. | 10 3 1 1 1
> 0 |
> 49. | 10 4 1 2 1
> 1 |
> 50. | 10 5 0 0 0
> 0 |
> +------------------------------------------+
>
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/