In this work, we report a study of GaN doping by Mg diffusion. GaN films were grown on sapphire or SiC substrates by MBE. The samples were characterized by Hall measurements and photoluminescence before and after the diffusion. The diffusion was performed in the following manner: Mg layer was deposited on the sample by thermal evaporation, followed by the deposition of a capping layer (metallic or SiO2). Samples were subsequently annealed in N2 flow at 850°C or 900°C for 6 hours. We show that Mg diffusion doping is feasible, and that the results are highly dependent on the capping layer. However, it should be pointed out that the obtained results for different samples with the same capping layer may show significant variations in spite of similar properties before the diffusion. This is most likely due to relationship between Mg doping and the presence of threading dislocations, which hinders the reproducibility of diffusion doping process.