/* ERGODIC.G: procedure to compute the invariant distribution of an ergodic markov chain. John Rust, Yale University, May, 2001. Input: an (n x n) Markov transition probability matrix p (each row must be positive and sum to 1) Output: an (n x 1) vector representing the invariant distribution of the Markov process, if it exists and is unique. If it does not exist or is not unique, the procedure returns a missing value code */ proc ergodic(p); local n,ap,y; n=rows(p); ap=eye(n)-p'; ap=ap|ones(1,n); ap=ap~ones(n+1,1); if (rank(ap) < n+1); "Error: transition matrix P is not ergodic"; retp(miss(0,0)); endif; y=ones(n,1)|2; y=inv(ap)*y; retp(y[1:n]); endp;