title: running program inside a loop in Stata
body: <p>I am trying to run a program inside a loop, but I am getting </p>
  
  <pre><code>-Break--
  r(1);
  </code></pre>
  
  <p>Here is my script:</p>
  
  <pre><code> clear all
      forvalues i=1/5{
      sysuse auto if rep78==`i'
      capture program drop testpro
      program define testpro,eclass
      preserve 
  
      tabstat price mpg headroom,stat(mean) save
      mat avg=r(StatTotal)
      ereturn post avg
      restore 
      end
      }
      --Break--
      r(1);
  
      end of do-file
  
      --Break--
      r(1);
  </code></pre>
  
  <p>Any help in this regard will be highly appreciated.</p>