Announcement

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

  • droping multiple observations

    My data looks like the one below.
    and I want to delete the observations that dont have hhid (the three empty cells) conditional that the 'test' variable/column is 1,2, and 3
    hhid test
    101014002017101 1
    101014002017101 2
    101014002017101 3
    101014002017101 4
    101014002028401 1
    101014002028401 2
    101014002028401 3
    101014002028401 4
    101014002029701 1
    101014002029701 2
    101014002029701 3
    101014002029701 4
    101014002029701 5
    101014002029701 6
    101014002029701 7
    101014002029701 8
    1
    2
    3
    101014002029701 4
    101014002040901 1
    101014002040901 2
    101014002040901 3
    101014002040901 4

  • #2
    Code:
    drop if hhid == .

    Comment


    • #3
      note that the response in #2 assumes that hhid is numeric; however, because of the way the data are posted in #1, we can't know whether it is numeric or string; so, please read the FAQ which has detailed advice on how to show data extracts; second, note that if hhid is string you should replace the response in #2 with
      Code:
      drop if hhid==""
      note that even this assumes that there are no stray "spaces" in hhid so you might want to use the "strtrim" function first (if hhid is a string variable)
      Code:
      help strtrim

      Comment


      • #4
        And if one does not want to bother thinking what is strings and what is numeric, the -missing()- function is very useful.

        Code:
        drop if missing(hhid)

        Comment


        • #5
          while Joro's point is correct, note that a single space (or more) is not considered missing for string variables so you may still want to use "strtrim" first (i.e., before applying the code showin in #4

          Comment

          Working...
          X