Announcement

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

  • Delete single observations

    Hello everyone,

    I have a dataset where I have to create couples of people in a way that every household consists of 2 partners. However some households still have only one member after using the relevant filters. Every person has one household id, refering to the household he/she belongs to, however there are still some household id's that only appear once, meaning there is only one person in this household. As a result I was wondering how I can drop all the observations where the number of people in a household(so with a certain hhid) is one.

    Thanks in advance

  • #2
    Michiel:
    welcome to this forum.
    With no data example/excerpt (see -help dataex-), I find difficult to reply positively.
    Maybe it's a job for the -group- function under -egen- (see -help egen-) to be used before -delete-.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      while I agree with Carlo that the absence of a data example makes it harder to answer (please read the FAQ), I have a different guess: use -egen- with the count function to count the number of occurrences of each household id - tabulate that count (my guess based on what you said is that you should have only 1's and 2's, but ...) - then -drop- if the new count variable is equal to 1

      Comment


      • #4
        No new variable is needed. No use of egen is needed.

        Code:
        bysort id : drop if _N == 1
        drops singleton panels.

        Comment

        Working...
        X