Dear community,
I am trying to see how many times using the Box-Jenkins methodology I select the correct ARIMA model for a set of observations generated by the correct (original) model. The code works fine for the first 100+ simulations. After that, the following message appears: "Flat log probability found, cannot find uphill address." It does not indicate on which line the problem occurs. I've read that it might be something to do with the arima command. How do I prevent stopping the code execution if that problem happens? I'll attach the code just in case.

Code:
clear all
set more off
* cambiar matsize a, J(aca,...) y forvalue j= 1(1)aca

set matsize 500
matrix simulaciones =J(500,3,0) //To save every simulation of every time series generated
matrix serie = J(500,3,0) //To save each time series
set obs 500 //For the 300 observations in every time series
gen t = _n
tsset t
g cont_1 =0
g cont_2 =0
g cont_3 =0
g cont_4 =0
g cont_5 =0
g cont_6 =0
g wn_1 = 0
g wn_2 = 0
g wn_3 = 0
g wn_4 = 0
g wn_5 = 0
g wn_6 = 0
g loop = 0

forvalue j = 1(1)1000{
g y1=0
    * Creating a time series
    forvalues i = 1(1)500 {
       qui gen e = rnormal(0,1)
       qui replace y1 = 0.5 + 0.9*L1.y1+ e + 0.5*L1.e if t > 1
        mkmat t y1 e, matrix(serie)
        drop e
    }

    * Modelo 1
 qui arima y1, arima(1,0,0)  
 mat R = r(table)
 mat p1 = R["pvalue", "ARMA:L.ar"]
 g sig_1 = 1 if p1[1,1] < 0.05
 qui estat ic
 mat T = r(S)
 g bic_1 = T[1,6]
 predict resid1, resid

 
 
    * Modelo 2
 qui arima y1, arima(2,0,0)  
 mat R = r(table)
 mat p1 = R["pvalue", "ARMA:L.ar"]
 mat p2 = R["pvalue", "ARMA:L2.ar"]
 g sig_2 = 1 if p1[1,1] < 0.05 & p2[1,1] < 0.05
 qui estat ic
 mat T = r(S)
 g bic_2 = T[1,6]
 predict resid2, resid
 
    * Modelo 3
 qui arima y1, arima(0,0,1)  
 mat R = r(table)
 mat p1 = R["pvalue", "ARMA:L.ma"]
 g sig_3 = 1 if p1[1,1] < 0.05
 qui estat ic
 mat T = r(S)
 g bic_3 = T[1,6]
 predict resid3, resid
 
    * Modelo 4
 qui arima y1, arima(0,0,2)  
 mat R = r(table)
 mat p1 = R["pvalue", "ARMA:L.ma"]
 mat p2 = R["pvalue", "ARMA:L2.ma"]
 g sig_4 = 1 if p1[1,1] < 0.05 & p2[1,1] < 0.05
 qui estat ic
 mat T = r(S)
 g bic_4 = T[1,6]
 predict resid4, resid
 
    * Modelo 5
 qui arima y1, arima(1,0,1)  
 mat R = r(table)
 mat p1 = R["pvalue", "ARMA:L.ar"]
 mat p2 = R["pvalue", "ARMA:L.ma"]
 g sig_5 = 1 if p1[1,1] < 0.05 & p2[1,1] < 0.05
 qui estat ic
 mat T = r(S)
 g bic_5 = T[1,6]
 predict resid5, resid
 
    * Modelo 6
 qui arima y1, arima(2,0,2)  
 mat R = r(table)
 mat p1 = R["pvalue", "ARMA:L.ar"]
 mat p1_2 = R["pvalue", "ARMA:L2.ar"]
 mat p2 = R["pvalue", "ARMA:L.ma"]
 mat p2_2 = R["pvalue", "ARMA:L2.ma"]
 g sig_6 = 1 if p1[1,1] < 0.05 & p2[1,1] < 0.05 & p1_2[1,1] < 0.05 & p2_2[1,1] < 0.05
 qui estat ic
 mat T = r(S)
 g bic_6 = T[1,6]
 predict resid6, resid

* egen min = min(mean bic_1, mean bic_2 )
 
 forvalue r = 1(1)6{
 set varabbrev off
 qui egen modelo_`r' = mean(bic_`r')
 qui replace modelo_`r' = 200000 if sig_`r' ==.
 }
  
 qui egen min = rowmin(modelo_1-modelo_6)
 
 forvalue x = 1(1)6{
 qui replace modelo_`x' = 1 if modelo_`x' == min
 }
 
 forvalue p = 1(1)6{
 qui replace cont_`p' = cont_`p' + 1 if modelo_`p' == 1
 }
 
  
 forvalue u = 1(1)6{
    if modelo_`u' == 1{
      qui wntestq resid`u'
      qui gen p = r(p)
      qui replace wn_`u' = wn_`u' + 1 if p > 0.05
      }
      }
drop p
drop min
drop y1

forvalue d = 1(1)6{
 drop modelo_`d'
 drop resid`d'
 drop bic_`d'
 drop sig_`d'
}
qui replace loop = loop + 1
}