Announcement

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

  • Drop panel-observations if data have no count

    Hi everyone

    I have the variables "year" (2009-2019) for each "company key" (e.g.: 1661) and two count variables (the other two columns) and want to drop all observations of a "company key" if every "year" per "company key" has no number.
    If a "company key" has a number in one "year", I want to keep every observations of the "company key".

    As you can see in the picture:
    1661 has no count and needs to be dropped.
    1690 has a count in 2010 and every observation should be kept.

    Thank you for your help!

    Best,
    Jana
    Attached Files

  • #2
    Jana, if the last two columns are missing or non-missing at the same time, then you may run the following codes.

    Code:
    bysort companykey: egen tempvar = total(lastcolumn), missing
    drop if tempvar == .
    drop tempvar
    Last edited by Fei Wang; 26 Oct 2021, 09:13.

    Comment


    • #3
      Code:
      bysort gvkey (whatever) : drop if missing(whatever[1])
      If after sorting the first value for each company is missing, then they all are.

      If you need that both variables should always be missing, you need a two-step:

      Code:
      bysort gvkey (something) : gen todrop = missing(something[1])
      bysort gvkey (whatever) : drop if todrop & missing(whatever[1])

      Examples using dataex are greatly superior (please) to images, deprecated at FAQ Advice #12
      Last edited by Nick Cox; 26 Oct 2021, 09:06.

      Comment


      • #4
        #2 needs a fix. The total of several missings is 0, not missing, unless you specify missing as an option.

        Comment


        • #5
          Nick Cox!
          Thank you very much.

          And also thanks for the hint, I will do that next time!

          Best,
          Jana

          Comment


          • #6
            Originally posted by Nick Cox View Post
            #2 needs a fix. The total of several missings is 0, not missing, unless you specify missing as an option.
            Thanks, Nick, for pointing this out. I have corrected #2 codes. And your solution is much neater.

            Comment


            • #7
              Fei Wang Thanks!

              https://en.wikipedia.org/wiki/On_the...you%27re_a_dog

              On the internet everyone knows you're a cat.... .

              Comment

              Working...
              X