title: Summarize which event came first
body: <p>I have panel data of individuals, their marital status (0 = not married, 1 = married) and one random shock (0 = No shock, 1 = Shock). Now for the people who experience the shock (Everyone except id1), I would like to know which person was already married when they experienced the shock (n=2, id3, id5), who was not married when they experienced the shock but subsequently got married (n=1, id2) and who was not married when they experienced the shock and did not get married subsequently (n=1, id4).</p>
  <pre><code>* Example generated by -dataex-. For more info, type help dataex
  clear
  input int year str3 id float(shock maritalstatus)
  2010 &quot;id1&quot; 0 1
  2011 &quot;id1&quot; 0 1
  2012 &quot;id1&quot; 0 1
  2013 &quot;id1&quot; 0 0
  2014 &quot;id1&quot; 0 0
  2015 &quot;id1&quot; 0 0
  2010 &quot;id2&quot; 1 0
  2011 &quot;id2&quot; 0 1
  2012 &quot;id2&quot; 0 1
  2013 &quot;id2&quot; 0 1
  2014 &quot;id2&quot; 0 1
  2015 &quot;id2&quot; 0 1
  2010 &quot;id3&quot; 0 1
  2011 &quot;id3&quot; 0 1
  2012 &quot;id3&quot; 0 1
  2013 &quot;id3&quot; 1 1
  2014 &quot;id3&quot; 0 1
  2015 &quot;id3&quot; 0 1
  2010 &quot;id4&quot; 1 0
  2011 &quot;id4&quot; 0 0
  2012 &quot;id4&quot; 0 0
  2013 &quot;id4&quot; 0 0
  2014 &quot;id4&quot; 0 0
  2015 &quot;id4&quot; 0 0
  2010 &quot;id5&quot; 0 1
  2011 &quot;id5&quot; 0 1
  2012 &quot;id5&quot; 1 1
  2013 &quot;id5&quot; 0 1
  2014 &quot;id5&quot; 0 1
  2015 &quot;id5&quot; 0 1
  end
  </code></pre>