Announcement

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

  • Dropping whole group if one group member has missing values

    Dear all,

    I have a dataset of all board members of German HDAX companies for a given year. I want to drop the whole company for a given year if one of the board members has missing values for age or gender.
    I have tried some of the suggestions here in the forum but unfortunately none of them worked for me.

    I hope someone can help me and many thanks in advance!

    [CODE]
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str80 boardname str57 directorname str12 isin int year str3(age gender)
    "KONTRON AG (S&T AG prior to 06/2022)" "Bernhard Chwatal"        "AT0000A0E9W5" 2014 "51" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Richard Neuwirth"        "AT0000A0E9W5" 2014 "42" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Peter Sturz"             "AT0000A0E9W5" 2014 "61" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Matthias Ehrlich"        "AT0000A0E9W5" 2014 "67" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Michael Jeske"           "AT0000A0E9W5" 2014 "50" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Hannes Niederhauser"     "AT0000A0E9W5" 2014 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Doctor Erhard Grossnigg" "AT0000A0E9W5" 2014 "75" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Michael Jeske"           "AT0000A0E9W5" 2015 "50" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Richard Neuwirth"        "AT0000A0E9W5" 2015 "42" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Peter Sturz"             "AT0000A0E9W5" 2015 "61" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Doctor Erhard Grossnigg" "AT0000A0E9W5" 2015 "75" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Matthias Ehrlich"        "AT0000A0E9W5" 2015 "67" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Hannes Niederhauser"     "AT0000A0E9W5" 2015 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Bernhard Chwatal"        "AT0000A0E9W5" 2015 "51" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Bernhard Chwatal"        "AT0000A0E9W5" 2016 "51" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Doctor Erhard Grossnigg" "AT0000A0E9W5" 2016 "75" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Hannes Niederhauser"     "AT0000A0E9W5" 2016 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Peter Sturz"             "AT0000A0E9W5" 2016 "61" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Michael Jeske"           "AT0000A0E9W5" 2016 "50" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Matthias Ehrlich"        "AT0000A0E9W5" 2016 "67" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Richard Neuwirth"        "AT0000A0E9W5" 2016 "42" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Bernhard Chwatal"        "AT0000A0E9W5" 2017 "51" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Hannes Niederhauser"     "AT0000A0E9W5" 2017 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Doctor Erhard Grossnigg" "AT0000A0E9W5" 2017 "75" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Michael Jeske"           "AT0000A0E9W5" 2017 "50" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Carlos Queiroz"          "AT0000A0E9W5" 2017 "67" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Hans Tsao"               "AT0000A0E9W5" 2017 ""   "."
    "KONTRON AG (S&T AG prior to 06/2022)" "Peter Sturz"             "AT0000A0E9W5" 2017 "61" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Richard Neuwirth"        "AT0000A0E9W5" 2017 "42" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Ed Wu"                   "AT0000A0E9W5" 2017 "73" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Steve Chu"               "AT0000A0E9W5" 2017 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Michael Jeske"           "AT0000A0E9W5" 2018 "50" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Richard Neuwirth"        "AT0000A0E9W5" 2018 "42" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Peter Sturz"             "AT0000A0E9W5" 2018 "61" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Carlos Queiroz"          "AT0000A0E9W5" 2018 "67" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Bernhard Chwatal"        "AT0000A0E9W5" 2018 "51" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Hans Tsao"               "AT0000A0E9W5" 2018 ""   "."
    "KONTRON AG (S&T AG prior to 06/2022)" "Doctor Erhard Grossnigg" "AT0000A0E9W5" 2018 "75" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Hannes Niederhauser"     "AT0000A0E9W5" 2018 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Steve Chu"               "AT0000A0E9W5" 2018 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Ed Wu"                   "AT0000A0E9W5" 2018 "73" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Max Lee"                 "AT0000A0E9W5" 2019 ""   "."
    "KONTRON AG (S&T AG prior to 06/2022)" "Hannes Niederhauser"     "AT0000A0E9W5" 2019 "59" "M"
    "KONTRON AG (S&T AG prior to 06/2022)" "Steve Chu"               "AT0000A0E9W5" 2019 "59" "M"

  • #2
    Thank you for using -dataex- on your first post!

    There is a slight ambiguity here. In Stata, the missing value for a string variable is "". I see that your gender variable has values "M", "F", and ".", and there are no instances of "". I'm going to assume that you intend "." to be treated as a missing value for gender. (Notably, the same does not occur with the age variable, hence my hesitancy.) This means first converting "." to "".

    Code:
    replace gender = "" if gender == "."
    by isin year, sort: egen to_drop = max(missing(age, gender))
    drop if to_drop
    As an aside, you will probably have difficulty working with age in its current status as a string variable. If you are not familiar with the -destring- command, do read -help destring-.

    Comment


    • #3
      Many thanks Clyde! Everything worked perfectly.
      And thanks for the hint with the -destring- command.

      Comment

      Working...
      X