Announcement

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

  • How to drop the data with the value of 3 times of ID in Stata?

    Hello, below is a small dataset,
    clear
    input str80 name int id
    "F-000509" 1
    "F-000703" 2
    "Future Bond Election" 3
    "F-000708" 4
    "F-000709" 5
    "F-000799" 6
    "F-000808" 7
    "F-000809" 8
    "F-000899" 9
    end
    I want to drop the data with the id=3,6,9. Because the real dataset is very large, the id can range from 1 to 10000000.
    So, I need Stata code to do this.
    Can someone help me in Stata?
    Thank you!
    Last edited by smith Jason; 17 May 2022, 08:38.

  • #2
    Code:
    drop if mod(_n,3)==0
    there is no variable in your example data (please read and follow the FAQ advice) so I use "_n" - you can, of course, substitute a variable name

    Comment


    • #3
      Thank you!

      Comment


      • #4
        I run your code, it can work. If I want to limit the id within a range, how could I write your code? For example, I want the id ranges from 3-17.
        I just run the code below,
        drop if mod(id,3)==0 & 2<id<18 However, it delete other values non-relevant. I don't understand. Thank you for your help!

        Comment


        • #5
          well, "2<id<18" is invalid; check
          Code:
          h inrange

          Comment


          • #6
            Code:
            if inlist(id, 3, 6, 9, 12, 15)

            Comment


            • #7
              Thank you!

              Comment

              Working...
              X