Announcement

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

  • Generation of variables

    Hey everyone,

    I´m having a question regarding the generation of variables. As you can see below, an excerpt of my dataset is shown. For my data analysis I want to create variables that show the name of the successor for each observation. I have already done this for numeric variables (using egen xx = total(y)), however I wasn´t able to generate these kind of variables for the exec_lname variable.

    The name of the successor (Horton in this example) should be shown at every observation with the same succession_id2.

    Thanks in advance!

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long gvkey double co_per_rol str20 exec_lname float(successor succession_id2 successor_id)
    1045 29349 "Reding"  . 2 166150
    1045 29348 "Kennedy" . 2 166150
    1045 14221 "Arpey"   . 2 166150
    1045 43629 "Goren"   . 2 166150
    1045 16477 "Garton"  . 2 166150
    1045 33126 "Horton"  1 2 166150
    end

  • #2
    What you ask for is only well-defined if only a single observation per succession_id2 group is designated with successor == 1. This code verifies that assumption, or actually the weaker assumption that if there is more than one such observation, they all agree on exec_lname, before proceeding.

    Code:
    //  VERIFY THAT ONLY ONE OBSERVATION IN SUCCESSION_ID2 GROUP IS DESIGNATED
    //  WITH SUCCESSOR == 1
    by succession_id2 (successor), sort: assert exec_lname == exec_lname[1] if !missing(successor)
    
    //  SPREAD NAME OF SUCCESSOR TO ENTIRE SUCCESSION_ID2 GROUP
    by succession_id2 (successor), sort: gen wanted = exec_lname[1] if !missing(successor[1])
    You did not indicate what should happen if there is no designated successor == 1 observation in a succession_id2 group, and perhaps that never occurs in your data. But if it does, the new variable will contain missing value (i.e. an emtpy string).

    Comment


    • #3
      Thank you so much, it worked out!

      Comment

      Working...
      X