Announcement

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

  • How to take individuals for which info is available in both waves only?

    Hi, I am working with BHPS dataset. I have appended Waves 9 & 10 and have declared it as panel. Using the command xtdes, I could see that not all info are available for all individuals in both waves and would want to drop individuals with info in either wave only. My unique identifier of each individual is pid. As you can see, some individuals have info in both waves (var wave) and some do not. How do I drop those individuals with data not available in both waves?
    Click image for larger version

Name:	Screenshot_2.png
Views:	1
Size:	35.9 KB
ID:	1484515

  • #2
    Adam:
    you may want to try:
    Code:
    bysort pid: g flag=1 if wave[2]==.
    drop if flag==1
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3

      Code:
      bysort pid : drop if _N == 1
      would seem sufficient.

      Comment


      • #4
        Nick is (as expected) right.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          I was on the verge of suggesting:

          Code:
          by pid, sort: keep if _N == 2
          But then I realized I was typing practically Nick's neat code!
          Best regards,

          Marcos

          Comment


          • #6
            It works! Thanks!

            Comment

            Working...
            X