Announcement

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

  • Dropping group of variables if the group does not contain a certain value

    Dear all,

    I am a stata beginner so this question might sound stupid. I have a dataset that list persons in a board of a public company for a given year. Moreover, I have specified whether someone is the CEO or not and if there has been a CEO succession event. The data is sorted by company and year. Now, I want to drop all the observations for a given company if there is no CEO succession event (for example, when the CEO remains in function in the whole period). If there is a CEO succession event, I want to keep all the observations (including the years where no succession is present). Looking at the screenshot below, I would like to drop all companies that look like that (where the CEO in the first year is also CEO in the last year). So, conceptually, all companies would be a separate group, then if this group (company) does not contain a ceo_change, the whole group gets dropped and if it does contain a ceo_change, the whole group stays.

    I hope someone can help me with this, thanks in advance!

    Click image for larger version

Name:	CEO data.jpg
Views:	1
Size:	613.7 KB
ID:	1597460

  • #2
    Code:
    bysort company role (time): egen x = min(cond(role=="CEO",individual[_n]==individual[_N],0))
    bysort company: egen y = max(x)
    drop if y
    drop x y

    Comment


    • #3
      Thanks for your reply, however I get the error 'individual ambiguous abbreviation'

      code:
      bysort company_name ceo_dummy (year): egen x = min(cond(ceo_dummy==1,individual[_n],0))
      bysort company_name: egen y = max (x)
      drop if y
      drop x y


      Instead of 'individualrole', I used 'ceo_dummy' as there are observations that include more text than just 'ceo' ('group ceo' for example). Therefore in the second part of the first line I changed the condition to ceo_dummy==1, indicating that someone is CEO. How could this be solved?

      thanks in advance

      Comment


      • #4
        Change individual to individual_name.

        Comment


        • #5
          This gives me 'type mismatch' error. I changed individual_name to a variable called 'directorid' which is basically then same but numerical.

          code:
          bysort company_name ceo_dummy (year): egen x = min(cond(ceo_dummy==1,directorid[_n],0))
          bysort company_name: egen y = max (x)
          drop if y
          drop x y


          However, if I run all these lines, it drops all observations which contain a CEO, leaving me with a dataset without CEOs. What did I do wrong?

          Thanks again for your help

          Comment


          • #6
            My error - I didn't realize your individual_name was a string. But in your amended code in #5, using the numeric variable, you omit an important part of the code. This should work:

            Code:
            bysort company_name ceo_dummy (year): egen x = min(cond(ceo_dummy==1,directorid[_n]==directorid[_N],0))
            bysort company_name: egen y = max(x)
            drop if y
            drop x y
            For future questions, please give a data example using -dataex-, which provides important information about your data and raises the likelihood that answers will work in the first instance.
            Last edited by Ali Atia; 12 Mar 2021, 08:42.

            Comment


            • #7
              Thanks, the code:

              bysort company_name ceo_dummy (year): egen x = min(cond(ceo_dummy==1,directorid[_n]==directorid[_N],0))
              bysort company_name: egen y = max(x)
              drop if y
              drop x y


              This code works, however, it drops 0 observations, which is weird. How could that be?

              Comment


              • #8
                It should work, see this made-up example where in company #1, the ceo is always directorid #4, leading to it being dropped:

                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float(company_name year directorid ceodummy)
                1 2001 3 0
                1 2002 4 1
                1 2003 3 0
                1 2004 4 1
                1 2005 4 1
                1 2006 3 0
                1 2007 5 0
                1 2008 4 1
                1 2009 4 1
                1 2010 1 0
                2 2001 3 1
                2 2002 1 0
                2 2003 4 0
                2 2004 3 1
                2 2005 1 1
                2 2006 3 1
                2 2007 5 1
                2 2008 5 0
                2 2009 3 1
                2 2010 1 1
                3 2001 3 0
                3 2002 3 1
                3 2003 1 0
                3 2004 4 1
                3 2005 5 0
                3 2006 5 0
                3 2007 3 0
                3 2008 2 1
                3 2009 1 0
                3 2010 5 1
                end
                bysort company_name ceodummy (year): egen x = min(cond(ceodummy==1,directorid[_n]==directorid[_N],0))
                bysort company_name: egen y = max(x)
                drop if y
                drop x y
                Code:
                . list ,sepby(company_name) noobs
                
                  +---------------------------------------+
                  | compan~e   year   direct~d   ceodummy |
                  |---------------------------------------|
                  |        2   2002          1          0 |
                  |        2   2003          4          0 |
                  |        2   2008          5          0 |
                  |        2   2001          3          1 |
                  |        2   2004          3          1 |
                  |        2   2005          1          1 |
                  |        2   2006          3          1 |
                  |        2   2007          5          1 |
                  |        2   2009          3          1 |
                  |        2   2010          1          1 |
                  |---------------------------------------|
                  |        3   2001          3          0 |
                  |        3   2003          1          0 |
                  |        3   2005          5          0 |
                  |        3   2006          5          0 |
                  |        3   2007          3          0 |
                  |        3   2009          1          0 |
                  |        3   2002          3          1 |
                  |        3   2004          4          1 |
                  |        3   2008          2          1 |
                  |        3   2010          5          1 |
                  +---------------------------------------+
                If it's not working, that means your data looks different to how I think it does. Please provide a data example by typing -dataex company_name ceo_dummy year directorid- and pasting the output between code delimiters.

                Comment


                • #9
                  When I type that, this is my output:

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input str128 company_name float ceo_dummy double(year directorid)
                  "1PM PLC"                                         0 2007  5899669191
                  "1PM PLC"                                         0 2007  5899749191
                  "1PM PLC"                                         0 2007  5899829191
                  "1PM PLC"                                         0 2007  5899909191
                  "1PM PLC"                                         0 2008  5899979191
                  "1PM PLC"                                         0 2008 63207812476
                  "1PM PLC"                                         0 2008  5899669191
                  "1PM PLC"                                         0 2008  5899749191
                  "1PM PLC"                                         0 2009  5899749191
                  "1PM PLC"                                         0 2009  5899979191
                  "1PM PLC"                                         0 2009  4855269108
                  "1PM PLC"                                         0 2009  5899669191
                  "1PM PLC"                                         0 2009 93753712245
                  "1PM PLC"                                         0 2010  5899749191
                  "1PM PLC"                                         0 2010 93753712245
                  "1PM PLC"                                         0 2010  5899669191
                  "1PM PLC"                                         0 2010  4855269108
                  "1PM PLC"                                         1 2010  5899979191
                  "1PM PLC"                                         0 2011  4855269108
                  "1PM PLC"                                         0 2011  5899749191
                  "1PM PLC"                                         0 2011  5899669191
                  "1PM PLC"                                         0 2011 93753712245
                  "1PM PLC"                                         1 2011  5899979191
                  "1PM PLC"                                         0 2012 93753712245
                  "1PM PLC"                                         0 2012  4855269108
                  "1PM PLC"                                         0 2012  5899669191
                  "1PM PLC"                                         0 2012  5899749191
                  "1PM PLC"                                         1 2012  5899979191
                  "1PM PLC"                                         0 2013  5899669191
                  "1PM PLC"                                         0 2013 93753712245
                  "1PM PLC"                                         0 2013  5899749191
                  "1PM PLC"                                         0 2013  4855269108
                  "1PM PLC"                                         1 2013  5899979191
                  "1PM PLC"                                         0 2014 93753712245
                  "1PM PLC"                                         0 2014  5899749191
                  "1PM PLC"                                         0 2014 14251427587
                  "1PM PLC"                                         0 2014  4855269108
                  "1PM PLC"                                         1 2014  5899979191
                  "1PM PLC"                                         0 2015  4855269108
                  "1PM PLC"                                         0 2015 93753712245
                  "1PM PLC"                                         0 2015 14251427587
                  "1PM PLC"                                         1 2015  5899979191
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006   693411741
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006 30148711102
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006  4780278417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006  4780268417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2006  4780258417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007 30148711102
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  4780278417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007   693411741
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  4780268417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  4780328417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007 53473312886
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  3601346990
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2007  4780258417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2008 53473312886
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2008  4780268417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2008  4780278417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2008  4780258417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009  4780278417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009 30148711102
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009  5524224997
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009 53473312886
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  5524224997
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  8757636849
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010 30148711102
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  4780278417
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  8757666849
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2010  8757616849
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011 11369553543
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011 11374993565
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011 11320683456
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011  5524224997
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2011  8757616849
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11374993565
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11428143671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012  5524224997
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11320683456
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11428173671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11428163671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2012  8757616849
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11428173671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11374993565
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11320683456
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013  5524224997
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11428143671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2013  8757616849
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014 11320683456
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014  5524224997
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014 11428143671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014 11428173671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014  5447713671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2014  8757616849
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015  5447713671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015  5524224997
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015 11320683456
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015 11428143671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015 11428173671
                  "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2015  8757616849
                  end

                  Comment


                  • #10
                    Using the code from #6 on your data example leads to company "1PM PLC" being dropped, because director #5899979191 is the CEO for the entire duration, but company "1SPATIAL PLC (Avisen PLC prior to 04/2012)" is retained because the CEO changes from 4780258417 to 8757616849. So I'm not sure why it's not working when you use it.

                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input str128 company_name float ceo_dummy double(year directorid)
                    "1PM PLC"                                         0 2007  5899669191
                    "1PM PLC"                                         0 2007  5899749191
                    "1PM PLC"                                         0 2007  5899829191
                    "1PM PLC"                                         0 2007  5899909191
                    "1PM PLC"                                         0 2008  5899979191
                    "1PM PLC"                                         0 2008 63207812476
                    "1PM PLC"                                         0 2008  5899669191
                    "1PM PLC"                                         0 2008  5899749191
                    "1PM PLC"                                         0 2009  5899749191
                    "1PM PLC"                                         0 2009  5899979191
                    "1PM PLC"                                         0 2009  4855269108
                    "1PM PLC"                                         0 2009  5899669191
                    "1PM PLC"                                         0 2009 93753712245
                    "1PM PLC"                                         0 2010  5899749191
                    "1PM PLC"                                         0 2010 93753712245
                    "1PM PLC"                                         0 2010  5899669191
                    "1PM PLC"                                         0 2010  4855269108
                    "1PM PLC"                                         1 2010  5899979191
                    "1PM PLC"                                         0 2011  4855269108
                    "1PM PLC"                                         0 2011  5899749191
                    "1PM PLC"                                         0 2011  5899669191
                    "1PM PLC"                                         0 2011 93753712245
                    "1PM PLC"                                         1 2011  5899979191
                    "1PM PLC"                                         0 2012 93753712245
                    "1PM PLC"                                         0 2012  4855269108
                    "1PM PLC"                                         0 2012  5899669191
                    "1PM PLC"                                         0 2012  5899749191
                    "1PM PLC"                                         1 2012  5899979191
                    "1PM PLC"                                         0 2013  5899669191
                    "1PM PLC"                                         0 2013 93753712245
                    "1PM PLC"                                         0 2013  5899749191
                    "1PM PLC"                                         0 2013  4855269108
                    "1PM PLC"                                         1 2013  5899979191
                    "1PM PLC"                                         0 2014 93753712245
                    "1PM PLC"                                         0 2014  5899749191
                    "1PM PLC"                                         0 2014 14251427587
                    "1PM PLC"                                         0 2014  4855269108
                    "1PM PLC"                                         1 2014  5899979191
                    "1PM PLC"                                         0 2015  4855269108
                    "1PM PLC"                                         0 2015 93753712245
                    "1PM PLC"                                         0 2015 14251427587
                    "1PM PLC"                                         1 2015  5899979191
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006   693411741
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006 30148711102
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006  4780278417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2006  4780268417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2006  4780258417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007 30148711102
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  4780278417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007   693411741
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  4780268417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  4780328417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007 53473312886
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2007  3601346990
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2007  4780258417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2008 53473312886
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2008  4780268417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2008  4780278417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2008  4780258417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009  4780278417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009 30148711102
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009  5524224997
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2009 53473312886
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  5524224997
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  8757636849
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010 30148711102
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  4780278417
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2010  8757666849
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2010  8757616849
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011 11369553543
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011 11374993565
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011 11320683456
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2011  5524224997
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2011  8757616849
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11374993565
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11428143671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012  5524224997
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11320683456
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11428173671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2012 11428163671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2012  8757616849
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11428173671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11374993565
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11320683456
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013  5524224997
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2013 11428143671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2013  8757616849
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014 11320683456
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014  5524224997
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014 11428143671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014 11428173671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2014  5447713671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2014  8757616849
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015  5447713671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015  5524224997
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015 11320683456
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015 11428143671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      0 2015 11428173671
                    "1SPATIAL PLC (Avisen PLC prior to 04/2012)"      1 2015  8757616849
                    end
                    format %16.0g directorid
                    . list company directorid if ceo_dummy==1,sepby(company)
                    
                         +---------------------------------------------------------+
                         |                               company_name   directorid |
                         |---------------------------------------------------------|
                     18. |                                    1PM PLC   5899979191 |
                     23. |                                    1PM PLC   5899979191 |
                     28. |                                    1PM PLC   5899979191 |
                     33. |                                    1PM PLC   5899979191 |
                     38. |                                    1PM PLC   5899979191 |
                     42. |                                    1PM PLC   5899979191 |
                         |---------------------------------------------------------|
                     47. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   4780258417 |
                     55. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   4780258417 |
                     59. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   4780258417 |
                     69. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     74. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     81. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     87. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     93. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     99. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                         +---------------------------------------------------------+
                    Code:
                    bysort company_name ceo_dummy (year): egen x = min(cond(ceo_dummy==1,directorid[_n]==directorid[_N],0))
                    bysort company_name: egen y = max(x)
                    drop if y
                    drop x y
                    Code:
                    . list company directorid if ceo_dummy==1,sepby(company)
                    
                         +---------------------------------------------------------+
                         |                               company_name   directorid |
                         |---------------------------------------------------------|
                     49. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   4780258417 |
                     50. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   4780258417 |
                     51. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   4780258417 |
                     52. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     53. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     54. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     55. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     56. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                     57. | 1SPATIAL PLC (Avisen PLC prior to 04/2012)   8757616849 |
                         +---------------------------------------------------------+

                    Comment


                    • #11
                      That's weird, I have again copy pasted the code that you wrote and it still does not work. Furthermore, when I look at variable x and y, they all give the value 0, which explains why nothing is dropped I think. Maybe that's where the mistake lies?

                      Comment


                      • #12
                        Here's an alternative, though I'm stumped as to why the code from #6 works on the data example but not on the actual data:

                        Code:
                        bysort company_name ceo_dummy: egen maxceo=max(directorid)
                        bysort company_name ceo_dummy: egen minceo=min(directorid)
                        bysort company_name: egen max = max(cond(ceo_dummy==1,maxceo==minceo,0))
                        drop if max
                        drop max* min

                        Comment


                        • #13
                          It seems to work now, thank you for your help!!

                          Comment


                          • #14
                            After some review, I have found another issue. The code works perfectly, however, there are some companies in my dataset that do not have a CEO at all. Do you perhaps know how I can modify the code so that it also drops the companies for which the ceo_dummy is always 0?

                            Comment


                            • #15
                              Code:
                              bysort company_name: egen maxdummy=max(ceo_dummy)
                              drop if maxdummy==0

                              Comment

                              Working...
                              X