Announcement

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

  • Identifying cases where the values of a given variable are missing for all observations in the group

    How can I check whether the values of a given variable are missing for all observations in a group?
    For example, I have unbalanced panel data for an organization spanning 18 years, and I have a location code variable. The location code is sometimes missing or missing all the time or not missing all the time for an organization. I want to identify which organizations have a missing location code for all the years.
    I used the following code

    bysort organization : gen Allmisslocationcode = missing(location code [1]) & missing(location code [_N])



    However, I encounter issues when using this variable because some locations may be missing for the first and last observations of the organization, but not missing for some observations in the middle. Even if Allmisslocationcode == 1 for cases where location codes are missing for all observations of the organizations, it also includes cases where some location codes are missing only for the first and last observations but not necessarily for some observations in the middle.

    Do you have any suggestions on how I should rearrange the above command to select only cases where the location codes are missing for all observations of the organizations?

    Or do you have other simple commands?

    Thank you, and I look forward to your tips.

  • #2
    The sufficient condition for a numerical variable once sorted is that the first value is missing.

    Code:
    bysort organization (location_code) : gen allmissing = missing(location_code[1])

    Comment


    • #3
      Thank you, Andrew Musau!!

      Comment

      Working...
      X