Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Drop duplicates depending on two variables

    Hi,

    I am totally new to Stata (Version 17.0). I´ve got a data set icluding the variables ticker (some kind of ID Code for each company, ZOTS and ZY in the extract below) and anndats (announcement dates) as well as multiple other variables.
    Now I need to drop all observations, where ticker and anndats are the same.

    Here is an extract from list ticker anndats:

    ZOTS 03nov2015
    ZOTS 16feb2016
    ZOTS 16feb2016
    ZOTS 04may2016
    ZOTS 04may2016
    ---------------------------

    ZY 15nov2016
    ZY 22feb2017
    ZY 22feb2017

    ZY 16may2017


    Like, for example, i want to drop the third, the fifth and the eigth row, but keep the rest. How do I do that?
    Last edited by sladmin; 15 Feb 2023, 07:10. Reason: anonymize original poster

  • #2
    Hello Guest. Welcome to Statalist. This FAQ should help you with your problem:
    Last edited by sladmin; 15 Feb 2023, 07:10. Reason: anonymize original poster
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

    Comment


    • #3
      Bruce Weaver That FAQ is flagged as for versions before 8. This is possible in 17.


      Code:
       
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str4 ticker float(anndats whatever)
      "ZOTS" 20395 1
      "ZOTS" 20500 2
      "ZOTS" 20500 3
      "ZOTS" 20578 4
      "ZOTS" 20578 5
      "ZY"   20773 6
      "ZY"   20872 7
      "ZY"   20872 8
      "ZY"   20955 9
      end
      format %td anndats
      [
      . duplicates drop ticker anndats, force
      
      Duplicates in terms of ticker anndats
      
      (3 observations deleted)
      
      . l
      
           +-------------------------------+
           | ticker     anndats   whatever |
           |-------------------------------|
        1. |   ZOTS   03nov2015          1 |
        2. |   ZOTS   16feb2016          2 |
        3. |   ZOTS   04may2016          4 |
        4. |     ZY   15nov2016          6 |
        5. |     ZY   22feb2017          7 |
           |-------------------------------|
        6. |     ZY   16may2017          9 |
           +-------------------------------+
      .

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Bruce Weaver That FAQ is flagged as for versions before 8. This is possible in 17.
        Ah yes, of course. I should have spotted that.

        This UCLA page has more up-to-date examples.
        Last edited by Bruce Weaver; 12 Feb 2023, 06:26.
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 19.5 (Windows)

        Comment

        Working...
        X