Stan can handle latent discrete parameters in population ecology models by marginalizing them out. This allows estimating quantities like population size and transition probabilities. Stan formulations for capture-recapture and multistate models use matrix calculations in hidden Markov models. Stan shows faster computation and better sampling than OpenBUGS for these examples, though the models can be more complex to specify in Stan.