You could explicitly record which of those three cases (0, 1, or 2 p-values < 0.1) you're in, and the logic to transition between them, but lets try a little numerical trick. Replace all of the if logic with,

Code: Select all

`!fake_aic = eq{!i}.@aic - 1000 * ((eq{!i}.@pval(2) < !pval_C) + (eq{!i}.@pval(3) < !pval_D))`

if !fake_aic < !aic then

!aic = !fake_aic

!bestlag_a = !lag_a

!bestlag_b = !lag_b

!bestlag_c = !lag_c

endif

The idea above is to create a score for the estimation, which I've called "fake_aic". The score is based on the AIC, but the score gets better as more p-values are less than the 0.1 threshold. If neither p-value is less then 0.1, then the score will just be the AIC. If only one p-value is less than 0.1, then the score will be the AIC - 1000, which will be better than all the possible scores for an estimation with no p-values less than 0.1. Similarly, if both p-values are less then 0.1, then the score will be AIC - 2000, which is better than all the possible scores for an estimation with one or no p-values less than 0.1. Defining the score this way allows you to preference more p-values less than 0.1 and use AIC as the tie-breaker.