title: extract quarter from date variable in Stata
body: <p>I am trying to extract the quarter from a date variable that looks like <code>dat</code> in the following example:</p>
  
  <pre><code>clear all
  
  input str20 str
      "12Jan1998"
      "29Dec2000"
  end
  
  gen dat = date(str, "DMY")
  format dat %tdDD-NN-CCYY
  </code></pre>
  
  <p>I am trying to use the <code>quarter()</code> function, like in:</p>
  
  <pre><code>gen quart = quarter(dofq(dat))
  </code></pre>
  
  <p>What I get is clearly wrong. Can you please suggest a way to solve this?
  According to the example, what I would like to get in the end is 1 and 4.</p>