Stopping the macOS installation may cause file corruption. But since a factory reset will erase all data on your Mac and reinstall a new operating system, the corruption part isn't really a concern. Just make sure you back up your Mac before taking any action.
- Press Command + Q to exit the installation window and then shut down your Mac. Or simply hold down the power button to force shut down your Mac.
- Hit the power button, then immediately press and hold Option + Command + R until the spinning globe shows up.
- Select "Reinstall macOS" and click Continue.
- Follow the onscreen instructions to install macOS.
If the installation still hangs for a long time, you can erase your startup disk and retry the installation again.