ladder function

Replica of Stata's ladder function