title: Stata: replace, if, forvalues
body: <pre><code>use "locationdata.dta", clear
  gen ring=.
  * Philly City Hall
  gen lat_center = 39.9525468
  gen lon_center = -75.1638855
  destring(INTPTLAT10), replace
  destring(INTPTLON10), replace
  vincenty INTPTLAT10 INTPTLON10 lat_center lon_center , hav(distance_km) inkm
  quietly su distance_km
  local min = r(min)
  replace ring=0 if (`min' &lt;= distance_km &lt; 1)
  local max = ceil(r(max))
  * forval loop does not work
  forval i=1/`max'{
      local j = `i'+1
      replace ring=`i' if (`i' &lt;= distance_km &lt; `j')
  }
  </code></pre>
  
  <p>I am drawing rings by 1 km from a point. The last part of the code (<code>forval</code>) does not work. Something wrong here?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The result for the <code>forval</code> part is as follows:</p>
  
  <pre><code>. forval i=1/`max'{
  2.         local j = `i'+1
  3.         replace ring=`i' if `i' &lt;= distance_km &lt; `j'
  4. }
  (1746 real changes made)
  (0 real changes made)
  (0 real changes made)
  (0 real changes made)
  ....
  </code></pre>
  
  <p>So, replacing does not work for <code>i = 2</code> and beyond.</p>