Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have generated a variable <code>time_to_event</code> which is -2 .. 2 in a window and missing otherwise. You can use <code>tsspell</code> from SSC, installed by </p> <pre><code> ssc inst tsspell </code></pre> <p>to label such windows. Windows are defined by spells or runs of observations all non-missing on that <code>time_to_event</code>: </p> <pre><code> tsspell, cond(time_to_event &lt; .) </code></pre> <p><code>tsspell</code> requires a prior <code>tsset</code> and generates three variables explained in its help. You can then renumber windows by using one of those variables <code>_seq</code> (sequence number within spell, numbered 1 up) </p> <pre><code> gen _spell2 = (_seq &gt; 0) * sum(_seq == 1) </code></pre> <p>and then label spells distinctly by using <code>country</code> and the spell identifier for each spell from <code>_spell</code>, another variable produced by <code>tsspell</code>:</p> <pre><code> egen gspell = group(country _spell) if _spell2, label </code></pre> <p>My code assumes that windows are disjoint and cannot overlap, but that seems to be one of your assumptions too. Some technique for handling spells is given by <a href="http://www.stata-journal.com/sjpdf.html?articlenum=dm0029" rel="nofollow">http://www.stata-journal.com/sjpdf.html?articlenum=dm0029</a> That article does not mention <code>tsspell</code>, which in essence is an implementation of its principles. I started explaining the principles, but the article got long enough before I could explain the program. As the help of <code>tsspell</code> is quite detailed, I doubt that a sequel paper is needed, or at least that it will be written. </p> <p>(LATER) This code also assumes that windows don't touch. Solving that problem suggests a more direct approach not involving <code>tsspell</code> at all: </p> <pre><code> bysort country (year) : gen w_id = (time_to_event &lt; .) * sum(time_to_event == -2) egen w_label = group(country w_id) if w_id, label </code></pre>
    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