We investigate effects of doping on formation energy and concentration of oxygen vacancies at a metal oxide surface, using MgO (100) as an example. Our approach employs density-functional theory, where the performance of the exchange-correlation functional is carefully analyzed, and the functional is chosen according to a fundamental condition on DFT ionization energies. The approach is further validated by CCSD(T) calculations for embedded clusters. We demonstrate that the concentration of oxygen vacancies at a doped oxide surface is largely determined by formation of a macroscopically extended space charge region.