Stable nitrogen doping is an important issue in p-type ZnO research for device applications. In this paper, beryllium and magnesium are systematically compared as a dopant in ZnO to reveal their nitrogen-stabilizing ability. Secondary ion mass spectrum shows that Be and Mg can both enhance the stability of nitrogen in ZnO while Be has a better performance. Zn 2p and O 1s electron binding energies change in both MgZnO and BeZnO thin films. Donor-acceptor luminescence is observed in the BeZnO samples. We conclude that Be is a better co-doping element than Mg for p-type ZnO:N.