I am working with panel data and I found the program xtpattern extremely
useful. Basically, it creates a string variable for each observation with
the patterns you would obtain by "xtdes" (describing) the data, sp say:
1.1..1
indicates that a unit of observation (say, a household) is present on time
periods 1,3 and 6.
What I need now is to know how many contiguous observations there are, so
for instance:
1.1..1 would be zero
111111 would be six
111.11 would be (perhaps) three (the max).
The obvious thing would be to parse through the string generated by
xtpattern... but I couldn't find an elegant way around this problem. Any
ideas on this?
Dick Campbell responded that if we changed the . to 0 and treated the
result as a binary number, we could get at the issue. Not quite sure this
will do that (especially in a language like Stata's that is a bit short on
bitwise operators--you really need a bitwise 'shift' here), since the issue
is the number of consecutive 1's. But Nick Cox (Harry Potter's sidekick)
has also provided a solution to that problem, known as