title: Dropping all id rows if at least one cell meets a given criterion (e.g. has a missing value)
body: <p>My dataset is in the following form:</p>
  
  <pre><code>clear
  
  input   id  var
  
              1   20      
              1   21      
              1   32      
              1   34     
              2   11     
              2   .     
              2   15     
              3   21     
              3   22    
              3   1     
              3   2
              3   5
  end
  </code></pre>
  
  <p>In my true dataset, observations are sorted by <code>id</code> and by <code>year</code> (not shown here).</p>
  
  <p>What I need to do is to drop <em>all</em> the rows of a specific <code>id</code> if (at least) one of the following two conditions is met:</p>
  
  <ol>
  <li>there is at least one missing value of <code>var</code>.</li>
  <li><code>var</code> decreases from one row to the next (for the same <code>id</code>)</li>
  </ol>
  
  <p>So in my example what I would like to obtain is:</p>
  
  <pre><code>       id  var
  
          1   20      
          1   21      
          1   32      
          1   34     
  </code></pre>
  
  <p>Now, my unfortuante attempt has been to use row-wise operations together with <code>by</code>, in order to create a <code>drop1</code> variable to be later used to subset the dataset.
  Something on these lines (which is clearly wrong), :</p>
  
  <pre><code>bysort id: gen drop1=1 if var[_n] &lt; var[_n-1] | var[_n]==.
  </code></pre>
  
  <p>This doesn't work, and I am not even sure that I am considering the most "clean" and direct way to solve the task.</p>
  
  <p>How would you proceed? Any help would be highly appreciated.</p>