Is data in an APFS container erased after main partition is reformatted? I am trying to create a data partition for my user account so as if I need to re-install my computer, I do not lose any data that is on the other partition.

If I had the following layout on my 512GB SSD:


macOS partition formatted as APFS + APFS container named MacData - 100GB
Shared Data partition formatted as ExFAT - 362GB
Bootcamp partition formatted as NTFS - 50GB


If I were to format and reinstall the OS on the partition called macOS, would I lose data on my MacData volume? This is if I erased the macOS container rather than the partition it self?
When Mojave is installed, you need to choose a APFS volume. However, the operating system is not just installed to this volume. Additionally, three other hidden APFS volumes (Preboot, Recovery and VM) are created, if they do not already exist. The preboot files are placed in a folder in the Preboot APFS volume and the recovery files are place in a folder in the Recovery APFS volume. In both cases, the name of the folder is the same as the UUID assigned to the APFS volume you chose when installing Mojave. The VM volume is used to store the sleep image and the swap file.

If you create a new APFS volume and install Mojave to this volume, then the three hidden volumes are reused. Again the preboot and recovery files are placed in a folders with a name the same as the UUID of the new APFS volume.

If you delete a APFS volume that was chosen for a Mojave installation, only this volume is removed. The three hidden volumes remain and still contain and the same files. To remove the folders containing the preboot and recovery files, you have to manually mount the volumes and remove the folders. (For example, use the diskutil mount command to manually mount each volume.) Since the space taken up by these folders and their contents is fairly small, most users will probably elect to just leave the folders intact on these hidden volumes.


  This is a long way of saying: The removal of Mojave by deleting a APFS volume does not alter any other APFS volumes.


What I wrote above also applies to High Sierra when installing to a APFS volume.