Context. Reliable atomic data are mandatory ingredients to obtain a realistic semiempirical model of any stellar atmosphere. Due to their importance, we further improved our recently published Mg I atomic model. Aims. We tested the new atomic model using atmospheric models of stars of different spectral types: the Sun (dG2), HD 22049 (dK2, Epsilon Eridani), GJ 832 (dM2), and GJ 581 (dM3). Methods. Significant improvements have been included in the atomic model, mainly to the electron impact excitation (ϒij) values. We used new Breit-Pauli distorted-wave (DW) multiconfiguration calculations, which proved to be relevant for many transitions in the mid-infrared (MIR) range. The new atomic model of Mg I includes the following: (i) recomputed (ϒij) data through the DW method, including the superlevels. (ii) For the nonlocal thermodynamic equilibrium (NLTE) population calculations, 5676 theoretical transitions were added (3001 term-to-term). (iii) All of these improvements were studied in the Sun and the stars listed above. Comparisons for the distribution of magnesium among the first ionization states and the formation of molecules, as well as for the population of the different energy levels and atmospheric heights, were carried out. Several lines, representative of the spectral ranges, were selected to analyze the changes that were produced. In particular, we exemplify these results with the problematic line 2853.0 Å, a transition between the third level and the ground state. Results. The magnesium distribution between ionization states for stars with different effective temperatures was compared. For the Sun and Epsilon Eridani, Mg II predominates with more than 95%, while for GJ 832 and GJ 581, Mg I represents more than 72% of the population. Moreover, in the latter stars, the amount of magnesium forming molecules in their atmosphere is at least two orders of magnitude higher. Regarding the NLTE population, a noticeable lower variability in the departure coefficients was found, indicating a better population coupling for the new model. Comparing the synthetic spectrum calculated with the older and new Mg I atomic model, these results show minimal differences in the visible range but they are stronger in the infrared (IR) for all of the stars. This aspect should be considered when using lines from this region as indicators. Nevertheless, some changes in the spectral type were found, also emphasizing the need to test the atomic models in different atmospheric conditions. The most noticeable changes occurred in the far-ultraviolet (FUV) and near-ultraviolet (NUV), obtaining a higher flux for the new atomic model regardless of the spectral type. The new model did not prevent the formation of the core emission in the synthetic NUV line 2853.0 Å. However, by including other observations, we could note that the emission indeed exists, although with a much lower intensity. Further tests have shown that to reduce the emission, the population of its upper level (3s3p 1P) should be reduced by a factor of about 100.