I am unfamiliar with STATA programming, and I am trying to program some very rudimentary optimization problems.

Suppose I have two variables: age and attitude. I want to find a cutoff in age such that I can minimize the MSE of predicting attitude with just a binary variable indicating whether age is above or below the cutoff.

I thought I could achieve that with the function nl and I wrote the following:

Code:
nl (attitude = {b0} + {b1}*(age>{cutoff}), hasconstant(b0)
but the result shows that both b1 and cutoff are constrained. How can I achieve what I want?

Also, what if I want to find the cutoff with another criteria? One potential idea is finding the cutoff that maximizes the Kolmogorov-Smirnov test statistics between the distribution of attitude among the two age groups.