Recent experiments on the injection of kiloampere electron beams into a magnetized plasma at the GOL-PET facility have shown that the power of sub-terahertz radiation escaping from the plasma along the magnetic field increases by more than an order of magnitude if strong transverse density gradients are preliminarily created in the plasma. In this paper, the influence of transverse in homogeneities of plasma density on the efficiency of electromagnetic radiation generation near the harmonics of the plasma frequency is studied using particle-in-cell simulations. Simulations performed for the real relative density of the beam and the real spatial scales of the in homogeneity show that the beam instability develops only in the density wells, and the small transverse size of its localization comparable with the wavelength contributes to a more efficient conversion of unstable oscillations into electromagnetic ones. Despite the fact that radiation at the plasma frequency is blocked across the leading magnetic field, it can leave the generation region with the decrease of the plasma density in the longitudinal direction.