[R] Computing and testing transition probabilities?
Ajay Shah
ajayshah at mayin.org
Sun Oct 3 20:41:46 CEST 2004
Folks, I have a situation with many firms, observed for many years
(but it's not panel data, so every now and then data for a firm just
goes missing).
Let me show you an example. There are 3 firms "a", "b" and "c". There
are 3 years: 1981, 1982 and 1983. There's a factor f which takes
values 1, 2 or 3.
set.seed(5)
D = data.frame(
names=c("a", "a", "a", "b", "b", "c", "c", "c", "d", "d"),
year= c( 81, 82, 83, 81, 83, 81, 82, 83, 82, 83),
f= sample(1:3, 10, replace=T)
)
print(D)
What I'd like to do is locate situations where a firm is observed for
two consecutive years, and put together conditional probabilities of
state transition.
Expressed as counts, putting time $t$ as the rows and time $t+1$ as
the columms, I'd like to get the table:
1 2 3
1 1
2 1
3 1 1 1
For example, this says that we only observe one situation (in this
data) where f=1 and then we got to see the next year, and in that year
f was 3. So we have a 100% probability of going from 1 -> 3. In the
case of f=3, we have 3 situations where we observe two consecutive
years where the 1st is f=3, and it turns out that the outcomes are
1,2,3 each happening once.
Expressed as conditional probabilities it is:
1 2 3
1 1
2 1
3 .33 .33 .33
How might one do this? And then, how might one go about getting
confidence intervals for the transition probabilities that are seen in
this transition matrix? I'd like to test the null that the state
variable does not change. I.e., if a firm is in f=2, under the null,
it's just stay at f=2 in the following year. That'd be an identity
matrix for the transition probabilities:
1 2 3
1 1
2 1
3 1
How does one talk about the distribution of the transition
probabilities under this null, and thus get a test?
--
Ajay Shah Consultant
ajayshah at mayin.org Department of Economic Affairs
http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
More information about the R-help
mailing list