Dear Professors,

Please, I have been trying to use a loop in finding an average point that gives a threshold effect on the dependent variable giving a criterion (such as lowest AIC or BIC). 

Y = a + bX + c(X-X*) + e
Where Y is the dependent variable,  and X is the independent variable.  

Please, if anyone has ever done something like appreciate it if the code can be shared. 

I am eager to learn. 

Thanks.
John