// Nov 13 2011 14:35:03 // Exploit maketrpr to calculate dynamic Hamming mata: // This function is not specific to this adofile and is repeated: should be in a central location real matrix function expandpwdist(real matrix raw, real matrix seqid, real matrix nd) { output = mm_expand(raw,nd,nd,1) return(output[invorder(seqid), invorder(seqid)]) } end mata: // Setup and work through all the pairs, calculating the DH distance real matrix function dynhamming (string vl, string sm, real scalar nstates, real scalar buzz, real scalar nrefs) { real scalar i,j,k real matrix subsmat, resmat st_view(data = .,.,(tokens(vl))) maxwidth = cols(data) nobs = rows(data) resmat = J(nobs, (nrefs==0 ? nobs : nrefs), 0) // (N*T) * N transition probability matrix subsmat = st_matrix(sm) // add p_{ij} to p_{ji} : would "x :+ x'" be better for (i = 1;i