Im converting a code written in PYTHON to STATA and I'm stuck at the point when have to apply the iterative procedure. Cannot find the way to write the loop so that it includes the initial value and generates an estimate for lat.

Has any of you got any experience with that and could share some wisdom with me?

Here is this bit of the code:

#Lat is obtained by an iterative proceedure:

lat = arctan2(z_2,(p*(1-e2_2))) #Initial value

latold = 2*pi

while abs(lat - latold)>10**-16:

lat, latold = latold, lat

nu_2 = a_2/sqrt(1-e2_2*sin(latold)**2)

lat = arctan2(z_2+e2_2*nu_2*sin(latold), p)

Many thanks in advance,

De