Translation from STATA to R

See the FAQ: How to do a minimal reproducible example reprex for beginners. In this case, a small amount of representative data for a, x and y, with an explanation of the transformation that ranksum represents. That is better than for answers based on guesses. Alternatively, perhaps someone versed in STATA may come across this.