title: Creating complete data in stata
body: <p>I have the following purchasing data    </p>
  
  <pre><code>clear 
  input id productid purchase
  1     1         1
  2     1         1
  3     2         1
  1     3         1
  end
  </code></pre>
  
  <p>I want to add a row for every id-productid combo to create the following dataset</p>
  
  <pre><code>id productid purchase
  1     1         1
  2     1         1
  3     1         0
  1     2         0
  2     2         0
  3     2         1
  1     3         1
  2     3         0
  3     3         0
  end
  </code></pre>
  
  <p>I have tried a lot that has not work. This is my latest.</p>
  
  <pre><code>qui sum id, d
  local obs = r(N) 
  expand = `obs'
  levelsof productid, local(id)
  local j = 1
  foreach i of local id {
      replace productid = `i' if `j' == id
      local j = `j' + 1
  }
  </code></pre>