Announcement

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

  • Stata Code for Excluding SIC Codes Ending with 0 & 9

    Hello guys,

    I need some kind of help. I download the full data but only need with SIC Code 2000 - 3999 (SIC Range) and exclude SIC codes ending with 0 and 9.
    I think I can use
    "drop if sic<2000
    drop if sic>3999"
    for the first condition. But I still can't figure it out how to satisfy the second condition (exclude SIC codes ending with 0 and 9) with a (simple) code. I really appreciate any kind of help.

    Thank you.

  • #2
    Based on your proposed code, I will assume that your variable sic is numeric, not string. (Your code will not work if that's not the case.) So with that, you can follow that code with:

    Code:
    drop if inlist(mod(sic, 10), 0, 9)
    Added: Actually, you can do it all in one command
    Code:
    keep if inrange(sic, 2000, 3999) & !inlist(mod(sic, 10), 0, 9)

    Comment


    • #3
      Welcome to Statalist.

      The mod function can be used to give you the last digit of the SIC code
      Code:
      drop if mod(sic,10)==0
      drop if mod(sic,10)==9
      You can combine all the conditions into one command.
      Code:
      keep if inrange(sic,2000,3999) & inrange(mod(sic,10),1,8)
      Your code and this code work if sic is a numeric variable; if it is a string, something else will be needed. That's one reason the Statalist FAQ encourages you to provide sample data. To improve future posts, please take a look at the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

      The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

      Added in edit: Crossed with the eerily similar post #2.

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        Based on your proposed code, I will assume that your variable sic is numeric, not string. (Your code will not work if that's not the case.) So with that, you can follow that code with:

        Code:
        drop if inlist(mod(sic, 10), 0, 9)
        Added: Actually, you can do it all in one command
        Code:
        keep if inrange(sic, 2000, 3999) & !inlist(mod(sic, 10), 0, 9)
        Yes, it is indeed numeric. Thank you for the kind help.

        Comment


        • #5
          Originally posted by William Lisowski View Post
          Welcome to Statalist.

          The mod function can be used to give you the last digit of the SIC code
          Code:
          drop if mod(sic,10)==0
          drop if mod(sic,10)==9
          You can combine all the conditions into one command.
          Code:
          keep if inrange(sic,2000,3999) & inrange(mod(sic,10),1,8)
          Your code and this code work if sic is a numeric variable; if it is a string, something else will be needed. That's one reason the Statalist FAQ encourages you to provide sample data. To improve future posts, please take a look at the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

          The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

          Added in edit: Crossed with the eerily similar post #2.
          Thank you for your advice and help. Yes, I will go through the Statalist FAQ then.

          Comment

          Working...
          X