title: Create a variable which is only a certain portion of a string variable in Stata
body: <p>I have a dataset which has a variable which has urls as its observations. I am trying to create another variable which would list the type of domain for the observation in the "url" variable (<code>.com</code>, <code>.org</code>, <code>.co.uk</code> etc.)</p>
  
  <p>I could split the "url" variable by parsing using "." </p>
  
  <p><code>split url, p(.)</code></p>
  
  <p>but that would not definitively give me the domain name.</p>
  
  <p>The problem arises due to the high variance in the type of "url"s For. eg.</p>
  
  <ul>
  <li>while <code>www.google.com</code> would be split into 3 variables, <code>http://www.nih.nlm.gov</code> would be split into 4</li>
  <li>similarly while <code>www.yahoo.com</code> is split into 3, <code>https://www.movies.yahoo.co.au</code> would be split into 5.</li>
  </ul>
  
  <p>How can i write the following formula in stata to create the "domain type" variable from the "url" variable</p>
  
  <blockquote>
    <p><ul>
    <li>if the part after the last "." in the "url" variable has ≥ 3 characters (.com/.edu/.org/.gov or .info) then use this as domain type</p>
    
    <blockquote>
      <p><ul>
      <li>if the part after the last "." in the "url" variable has &lt; 3 characters ( .uk/.au/.tv etc.) <strong>AND</strong> the part before the last "." has ≤ 2 characters (.co ), then use the part after the penultimate "." as domain type (i.e. .co.uk)</p>
      
      <blockquote>
        <p><ul>
        <li>if the value after the last "." in the "url" variable has &lt; 3 characters ( .us domains) <strong>AND</strong> the part before the last "." has > 2 characters, then use the part after the last "." as domain type (e.g freeshootinggames.us)</li>
        </ul></li>
        </ul></li>
        </ul></p>
      </blockquote>
    </blockquote>
  </blockquote>
  
  <p>Also, is there another way of doing this ?</p>
  
  <p>I am working in Stata 13.1 on Windows 8 Pro x64</p>
  
  <p>Thanks !!</p>