After inspecting the respective source codes I think the problem with Stata's implementation lies in fact that the subsamplesubset size used in each local regression depends on the ordinal position of the X values. That is, for extreme and near-extreme values of X (in other words, for values close to the tails), Stata uses a smaller subsamplesubset than for more central X's. Intuitively, the problem can be illustrated using a simple example with 100 data points where the bandwidth parameter is chosen to be 0.4 so that each subsamplesubset is of the size 0.4*100=40. In R, the size of the subsamplessubsets used for estimating $Y_1$, $Y_{10}$, $Y_{20}$, $Y_{30}$ and $Y_{40}$ would look like this:
On the other hand, Stata seems to reduce the size of the subsamplessubsets for all X's from (roughly) 1 to 20 and from 80 to 100:
When I rewrote the ksm
program such that the subsamplesubsets size was held fixed for all X's, I got the same results as in R (or Python). Below are the pseudo-codes of both implementations: