Suppose I have the following (toy) code
Code:
import stata_setup
stata_setup.config("C:/Program Files/Stata17", "mp")

for i in range(1000):
 %stata replace y=2
and I run the whole thing in python. Suppose Stata throws an error that variable y does not exist. If it were the real Stata, this would stop the program, and I would be happy. But in python, it will be executed 1000 times! Is there any way to stop it on its own?