Announcement

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

  • by Names , replacing missing values with Dummy variables (0,1)

    Dear Statamembers,


    This is my data looks like:


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double YEAR str50(FULL_NAME CONAME) str88 NAME str45 EMPLOYER float DUMMY byte _PS
    2012 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           "THERMO FISHER SCIENTIFIC" 1 3
    2013 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           ""                         . 1
    2014 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           "THERMO FISHER SCIENTIFIC" 1 3
    2015 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           "THERMO FISHER SCIENTIFIC" 1 3
    2016 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           "THERMO FISHER SCIENTIFIC" 1 3
    2017 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           ""                         . 1
    2018 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           "THERMO FISHER SCIENTIFIC" 1 3
    2019 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           "THERMO FISHER"            1 3
    2020 "Marc N. Casper"           "THERMO FISHER SCIENTIFIC INC" "CASPER, MARC"           "THERMO FISHER SCIENTIFIC" 1 3
    2016 "Safra Ada Catz"           "ORACLE CORP"                  "CATZ, SAFRA"            ""                         . 1
    2018 "Safra Ada Catz"           "ORACLE CORP"                  "CATZ, SAFRA"            "ORACLE"                   1 3
    2019 "Safra Ada Catz"           "ORACLE CORP"                  "CATZ, SAFRA"            "ORACLE"                   1 3
    2020 "Safra Ada Catz"           "ORACLE CORP"                  "CATZ, SAFRA"            ""                         . 1
    2012 "Clarence P. Cazalot, Jr." "MARATHON OIL CORP"            "CAZALOT, JR., CLARENCE" ""                         . 1
    2013 "Clarence P. Cazalot, Jr." "MARATHON OIL CORP"            "CAZALOT, JR., CLARENCE" ""                         . 1
    2017 "Andrew J. Cecere"         "US BANCORP"                   "CECERE, ANDREW"         ""                         . 1
    2018 "Andrew J. Cecere"         "US BANCORP"                   "CECERE, ANDREW"         ""                         . 1
    2019 "Andrew J. Cecere"         "US BANCORP"                   "CECERE, ANDREW"         "US BANK"                  0 3
    2020 "Andrew J. Cecere"         "US BANCORP"                   "CECERE, ANDREW"         ""                         . 1
    end

    I am struggling with such issue,

    By using "NAME" as an identifier, I need to replace the missing values for the same name with 1 or zero , depending on the other observations in other years for the same name

    for example, if the name in any year takes the dummy =1, I want to replace the other MISSING observations for such NAME by 1


    and the same for ZERO, if the name in any year takes the dummy = 0, I want to replace the other missing observations for such Name by 0

    I tried this code, but it seems wrong as it replaces all missing observations for all names

    Code:
    bysort NAME :replace DUMMY=1 if missing(DUMMY)

    Could anyone provide any suggestions/code to solve this issue?


  • #2
    What do you want to do if for the same name the value of DUMMY is 0 in some years and 1 in others?

    Comment


    • #3
      I suggest that

      Code:
      bysort NAME :replace DUMMY=1 if missing(DUMMY)
      will do nothing different from
      Code:
        
       replace DUMMY=1 if missing(DUMMY)
      and so won't change any value in any observation with non-missing DUMMY.

      Comment

      Working...
      X