Announcement

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

  • Keep if

    Hi guys!

    In my database I have a panel data of results of a test for multiple schools. However I have to work with 47 of them and each school has a unique id to identify each one. RBD is de ID of each school so I wanted to use the keep if command and write the every id of the 47 schools that I'm working with.

    Code:
    keep if rbd==7929 | rbd==7987 | rbd==7874 | rbd==7887 | rbd==7927 | rbd=7968 | (...)
    However after the sixth condition, stata shows me an error
    Code:
    =exp not allowed
    r(101);
    I don't know what the problem is, so I'd really appreciate your help.

    Thanks!

  • #2
    Typo: you need

    Code:
     
     rbd==7968
    not
    Code:
      
     rbd=7968 
    However, check out
    Code:
    inlist()
    e.g. https://www.stata-journal.com/articl...article=dm0026 and https://www.stata.com/support/faqs/d...s-for-subsets/

    Comment


    • #3
      Hello Fernando. You said in #1 that you want to keep 47 schools. How many schools do you want to exclude? I ask, because if the number you want to exclude is lower, you can shorten your code by using -drop- with the shorter list rather than -keep- with the longer list.

      Code:
      keep if inlist(rbd, comma-separated list of rbd values to keep)
      drop if inlist(rbd, comma-separated list of rbd values to drop)
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 19.5 (Windows)

      Comment

      Working...
      X