Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For each combination of components to be totally new for each distinct Player, it is necessary and sufficient that all components occur for the first time for that Player. Therefore we keep track of first occurrences of each component and drop any observations with later occurrences of that component. </p> <p>The same toy data (but with some shorter variable names): </p> <pre><code>input Product Player_id C1 C2 C3 1 1 1 2 3 2 1 1 5 9 3 1 7 8 9 4 2 4 5 6 5 2 4 5 9 6 2 7 8 9 end </code></pre> <p>It is not clear whether <code>Product</code> plays the same role as observation number: regardless of that we can create a variable holding observation numbers. </p> <pre><code>gen long obs = _n </code></pre> <p>Now we are going to loop over components, 9 of them in this example. </p> <pre><code>qui forval i = 1/9 { </code></pre> <p>For each component: it's found if it's any of the three components. That is an indicator variable, 1 if true and 0 if false: </p> <pre><code> gen found = C1 == `i' | C2 == `i' | C3 == `i' </code></pre> <p>There is a neat alternative: </p> <pre><code> gen found = inlist(`i', C1, C2, C3) </code></pre> <p>We want to keep track of the first occurrence, which is the minimum observation number if <code>found</code> is true, and we do that separately by <code>Player_id</code>. The division here by the indicator variable produces <code>obs</code> if <code>found</code> is 1 and missing otherwise. The missings are just ignored by <code>egen</code> unless all values are returned as missing. </p> <pre><code> egen first = min(obs / found), by(Player_id) </code></pre> <p>Now what we do is <code>drop</code> occurrences if they are not the first, and <code>drop</code> our accounting variables, so they can be re-created next time round the loop: </p> <pre><code> drop if obs &gt; first &amp; found drop first found } </code></pre> <p>Here's the result: </p> <pre><code> +-----------------------------------------+ | Product Player~d C1 C2 C3 obs | |-----------------------------------------| 1. | 1 1 1 2 3 1 | 2. | 3 1 7 8 9 3 | 3. | 4 2 4 5 6 4 | 4. | 6 2 7 8 9 6 | +-----------------------------------------+ </code></pre> <p>Note that this algorithm is sensitive to the order of the observations. If you start with <code>1 5 9</code> then neither <code>1 2 3</code> or <code>7 8 9</code> are acceptable in addition. Similarly with <code>4 5 9</code>; <code>4 5 6</code> and <code>7 8 9</code> don't make the cut. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload