title: Loop to save multiple files
body: <p>I would like to import multiple Excel files from a folder into Stata and save them as separate dta files. Each year has 4 quarters worth of sheets. Within each quarter, there are 60 sheets. I want to import each sheet individually.</p>
  <p>E.g.</p>
  <blockquote>
  <p>2004 Quarter 1 has Sheet 1- to save into 2004Q11.dta</p>
  <p>2004 Quarter 1 has Sheet60- to save into 2004Q60</p>
  </blockquote>
  <p>Is there a way to write it in a loop for speed?</p>
  <pre><code>local quarter q1 q2 q3 q4
  local i= 0
  foreach q of quarter {
      foreach a of numlist 1/10 {
          import excel &quot;2012`quarter'data&quot;, sheet(&quot;Sheet`i'&quot;) clear
          save &quot;2012`quarter'`i'.dta&quot;, replace
      }
  }
  </code></pre>