Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Patterns of longitudinal data

From   Dick Campbell <>
To   "" <>
Subject   st: Patterns of longitudinal data
Date   Sat, 10 Aug 2002 08:24:01 -0500

Guillermo Cruces said:

I am working with panel data and I found the program xtpattern extremely useful.
What I need now is to know how many contiguous observations there are, so for
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 p

xtpattern generates a string variable in the form 1.11.1 etc.
This can be interpreted as a binary number. Suppose there
are three observations maximum and we create the decimal
equivalent of the binary numbers resulting from xtpattern.
The fist position expands as 2**2, the second as 2**1
and the third as 2**0 (= 1). Thus for each pattern of observations
there is a unique decimal number,
Here is an example for four possible patterns.
111 = 7
11. = 6
1.1 = 5
1.. = 4

A neat characteristic of the decimal number is that
the higher the number of consecutive observations at the beginning of the
series the higher the decimal number. The second observation has a higher number than the third.
etc. You will also see that "consecutive observations always generate higher numbers
that non-consecutive, regardless of pattern.

Richard T. Campbell
Professor of Sociology
Phone: 312/413-3759
Fax: 312/996-5104
More info:

* For searches and help try:

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