title: Transform string monthly dates in Stata
body: <p>I have a problem in Stata with the format of the dates. I believe it is a very simple question but I can't see how to fix it. </p>
  
  <p>I have a csv file (file.csv) that looks like</p>
  
  <pre><code>v1            v2
  01/01/2000    1.1
  01/02/2000    1.2
  01/03/2000    1.3
  ...    
  01/12/2000    1.12
  01/02/2001    1.1
  ...
  01/12/2001    1.12
  </code></pre>
  
  <p>The form of v1 is dd/mm/yyyy. </p>
  
  <p>I import the file in Stata using <code>import delimited ...file.csv</code></p>
  
  <p>v1 is a string variable, v2 is a float. </p>
  
  <p>I want to transform v1 in a <strong>monthly</strong> date that Stata can read. </p>
  
  <p>My attempts:</p>
  
  <p>1)</p>
  
  <pre><code>gen Time = date(v1, "DMY")
  format Time %tm
  </code></pre>
  
  <p>which gives me </p>
  
  <pre><code>Time
  3177m7
  3180m2
  3182m7
  ...
  </code></pre>
  
  <p>that looks wrong.</p>
  
  <p>2) In alternative</p>
  
  <pre><code>gen v1_1=v1
  replace v1_1 = substr(v1_1,4,length(v1_1))
  gen Time_1 = date(v1_1, "MY")
  format Time_1 %tm
  </code></pre>
  
  <p>which gives exactly the same result.</p>
  
  <p>And if I type</p>
  
  <pre><code>tsset Time, format(%tm)
  </code></pre>
  
  <p>it tells me that there are gaps but there are no gaps in the data. </p>
  
  <p>Could you help me to understand what I'm doing wrong?</p>