Announcement

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

  • Removing specific observations

    Hello everyone,
    Based on my title post it seems the question is repeated but no it’s different.
    my question is:
    I have dataset file consists of a number of independent directors variable. I have created a dummy variable coded 1 if there is at least one independent director on the committee.
    I need to remove the firms that have no independent directors on the committee. Maybe it seems to be easy by dropping the observations== 0 ( using either the dummy variable or the variable of number of independent directors). But, I Need to remove those firms with no independent directors over the study period (2000-2006). This means that the remaining observations should consist of a firm that ( for example) did have no independent in the year 2000 then it appointed independent directors in 2001 or 2002.
    Because I want to compare between the firm performance before appointing independent directors and after.
    kindly who can help me out to do this and create dummy variable coded 1 after appointing independent directors zero before.

    please please help.
    thank you in advance

  • #2
    I suppose I could give you some code that will work with the data I imagine you have. But you'd probably prefer code that works with your actual data.

    So you need to show an example of the data. Please use the -dataex- command to do that. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Whenever you want help with code, always show example data, and always use -dataex- to do that.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      I suppose I could give you some code that will work with the data I imagine you have. But you'd probably prefer code that works with your actual data.

      So you need to show an example of the data. Please use the -dataex- command to do that. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

      Whenever you want help with code, always show example data, and always use -dataex- to do that.
      thank you so much
      here is the example
      HTML Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double num_of_ac_indep float board_indp double(board_size ceo_duality number_of_board_meetings) float(firm_size2 leverage) double(roa btm1) float(complex TOP10_Big4) long OPinion double soe float LOSS
      2 .3636364 11 0  6 18.170822   .6098095  .065178 1.331532      .7244214 1 1 1 0
      . .3636364 11 0  5  19.11299   .6494181  .047589  .721526       .656401 1 1 1 0
      2 .3636364 11 0  4 18.170822   .6744409  .038913 1.718787      .7281446 1 1 1 0
      . .3636364 11 0  4  16.43101   .6700168  .046727 1.187209      .6598317 1 1 1 0
      . .3636364 11 0  5 18.721848   .7468613  .040993  2.38766      .6257142 1 1 1 0
      2 .3636364 11 0  5 15.407593   .7709973   .03916 3.679669      .7084548 1 1 1 0
      . .3636364 11 0  4 18.721848    .783163  .041348 3.403011      .6785892 1 1 1 0
      0 .3636364 11 0  4  16.43101   .7799703  .038183 5.300902      .6974301 1 1 1 0
      2 .3636364 11 0  5  15.83524   .7720464  .037937 3.313807      .6286682 1 1 1 0
      . .3333333  9 0 12  14.08364   .3588438 -.119186  .448332      .5454849 0 1 1 1
      . .3333333  9 .  8 12.608055    .450415  .014954  .593384      .4198245 0 1 1 0
      .     .375  8 1  8 12.608055   .4241836 -.058897  .203038     .22838853 0 1 1 1
      . .3333333  9 0  8 12.608055   .4917934 -.068435   .56132     .29626638 0 1 1 1
      . .3333333  9 0  8  12.75899   .2985743  .109659  .182201      .2572849 0 1 0 0
      .     .375  8 0  9 13.464143  .29493517   .04683  .288954     .23652054 0 1 0 0
      . .3333333  9 0  9  14.08364   .2325276  .040506  .280835     .29704362 0 1 0 0
      2 .3333333  9 0  5 13.439986   .4032394  .023938  .247516      .3535287 1 1 0 0
      . .3333333  9 0  5 13.464143  .53475446  .046189  .258721     .58191276 1 1 0 0
      . .3333333  9 1  8 12.749282   .5904017    .0172   .10343      .6303461 1 1 0 0
      2 .3333333  9 1 11 12.608055   .2034563   .17753  .059332     .03842223 1 1 0 0
      . .3333333  9 1  7  14.08364   .3152466  .021917  .143048      .0903663 1 2 0 0
      . .3333333 15 1  4 15.136938   .5983874 -.109479 1.414444     .19106297 0 2 0 1
      . .3333333 15 1  6 16.178976   .5408641  .035869  .671279      .1809205 0 2 0 0
      . .3333333 15 0  7 16.178976   .4850051  .053105  .224126      .0828607 0 1 0 0
      3 .3333333 15 0  7 15.136938   .4586451  .007559   .61257     .06349902 0 1 0 0
      . .3333333 15 0  5  13.96583  .46757495 -.037083  .239668     .02986975 0 2 0 1
      . .3333333 15 0  8  14.25959   .4779603 -.003422  .385507     .05006535 0 2 0 1
      . .3333333 15 0 11 14.814513   .4831415  .016687  .485976     .11791206 0 2 0 0
      3 .3333333 15 0  8 15.136938  .47483096 -.035624  .520009    .014485708 0 2 0 1
      . .3333333 15 0  6 14.814513   .5099636  .031583  .364563     .01260065 0 2 0 0
      . .3333333 15 0  7 15.521038     .44704 -.024627  .206442      .1739892 0 2 0 1
      3 .3333333 15 0 15 15.076618   .4637085  .046281  .353177      .2294158 0 2 0 0
      . .3333333 15 0 10  13.96583  .51774734  .007876  .664508     .20919652 0 2 0 0
      .     .375  8 1  6  16.06864   .5575794  .040822 2.357764      .5474272 0 1 1 0
      . .3333333  9 0 32 14.101708   .5455816  .073814   .85834      .4539848 0 1 1 0
      2 .3333333  9 0  6 14.101708   .6774184  .045328  .839704      .6372778 0 1 1 0
      . .3333333  9 0  5  15.03948   .7166752  .025367 2.368185      .8318025 0 1 1 0
      2 .3333333  9 0  5 14.731967   .6985768  .046098 1.265496       .744714 0 1 1 0
      . .3333333  9 0  3 14.731967   .7014206  .057942 1.615868      .6858501 0 1 1 0
      . .3333333  9 0 16 14.731967   .6528552  .052165  2.05231      .7497571 0 1 1 0
      3 .3333333  9 0 27 14.101708    .620165  .067381 1.468109      .6183752 1 1 1 0
      . .3333333  9 0 21 14.101708  .57997173  .070024 1.497738      .5546773 1 1 1 0
      . .3333333  9 0 14 14.731967   .6414202  .043601  1.23491      .5810655 1 1 1 0
      .     .375  8 . 11 14.731967   .6461508  .034541  .817553      .6628816 1 1 1 0
      .     .375  8 . 19 14.101708   .6104992  .061037 1.032368     .58522725 1 1 1 0
      . .3636364 11 0  6  14.07811   .8729908  .012049 1.847623      .3132051 0 2 0 0
      . .3636364 11 0  6 13.432887   .9787455 -.123648 1.800376     .23768215 0 2 0 1
      2 .3636364 11 0 10 13.432887   1.011334  .011779  .529989     .03251128 0 2 0 0
      2 .3333333  9 0 10  14.07811  1.1226147 -.106456  1.01896     .04101475 0 2 0 1
      . .3333333  9 0  6 14.273855  1.1498989  .056213  .279374     .07352124 0 2 0 0
      . .3333333  9 0  8  14.07811   1.098531  .065279    .2102      .0800353 0 2 0 0
      2 .3333333  9 0 11  13.09262   .1934204  .022931   .23847     .06320793 0 1 0 0
      . .3333333  9 0  9 13.432887   .6241584  .005614  .236285      .0972988 1 1 0 0
      .     .375  8 0 11  14.07811  .46275425  .028639  .205101     .07985184 1 1 0 0
      2       .5  6 0  9  14.07811   .4742944 -.049025  .201929     .10913634 1 2 0 1
      2     .375  8 0 21  13.93653   .2238475   .02756  .087424     .09671536 1 1 0 0
      4 .3333333  9 0 25  14.07811  .14996207  .158579  .086892    .033265058 1 1 0 0
      .       .5  6 0  7 12.608306   .2493671 -.061412  .303109     .18054953 0 1 0 1
      .       .5  6 0  4  17.08053 .069083974 -.022854  .250178     .09080378 0 1 0 1
      .       .5  6 0  6 14.303369  .07428998  .021271  .086525             0 0 1 0 0
      2 .4285714  7 0 10 14.303369 .062781475  .009479  .242405             0 0 1 0 0
      .       .5  8 0  5 13.689527   .0765887  .003948  .087796 .000031440166 0 1 0 0
      2       .5  6 0 10 12.608306  .04531932  .011407  .088396    .012972947 0 1 0 0
      .       .5  6 0  5 12.608306  .04370549 -.006984  .150452     .03026162 0 1 0 1
      .       .5  6 0  7 17.161304  .11893076  .063746  .376855     .03691619 1 1 0 0
      3 .4285714  7 0  7 17.020708  .10060482  .036318   .22933    .022662396 1 1 0 0
      . .4285714  7 0  7 17.161304  .11227616  .011522  .100503     .02167795 1 1 0 0
      2 .4285714  7 0  9 12.608306  .18980925  .052909  .126461     .29306448 1 1 0 0
      2 .4285714  7 0 14  17.08053   .2465831  .064758  .312928     .27458513 1 1 0 0
      . .4285714  7 0 18 17.161304   .3269488   .08331  .433015       .299014 1 1 0 0
      .     .375  8 1  7 16.785557   .6498251  .023321 2.206978     .52062124 0 2 1 0
      .     .375  8 1  8 16.785557   .6464189  .028433 1.358812     .55799735 0 1 1 0
      .     .375  8 1 10 16.785557   .5912806  .056781  .383028      .3923073 0 1 1 0
      .     .375  8 1  8 16.721968   .5899989  .044634 1.471482      .4332891 0 1 0 0
      2     .375  8 1  9 15.384884   .6020921  .054465  .626397      .3252411 0 1 0 0
      2 .3333333  9 1 14  16.29114     .62953  .044051  .548038      .4522502 0 1 0 0
      . .3333333  9 1 15  16.29114   .6504021   .03228   .99129       .518988 0 1 0 0
      0 .3333333  9 1 13 16.785557   .6436691  .023331 1.372213      .4669373 0 1 0 0
      2     .375  8 1 13 16.721968   .6287978   .03263 1.148314      .4750378 0 1 0 0
      . .4285714  7 1 15 16.785557   .6289341  .032091  .755432     .46938315 0 1 0 0
      . .4285714  7 1 13  16.29114   .6382021  .053324  .633482       .398017 0 1 0 0
      . .3333333  9 1  8  16.29114   .6331205  .011924 1.744522     .40972975 0 1 0 0
      . .3333333 15 .  6 14.641724   .7912487 -.233876  .852536      .4364997 0 2 0 1
      . .3571429 14 .  8  14.58138   .6457486  .047287  .309087      .3450458 0 1 0 0
      1        .  . . 10 13.573532   .6463135  .090773  .266417      .6275051 0 1 0 0
      2 .3636364 11 1  8 13.573532   .6386543  .041536  .132973      .5827234 0 2 0 0
      2 .3636364 11 0 10 13.573532   .6022388  .014986  .087217      .6901931 0 1 0 0
      2 .3636364 11 0 17 13.573532   .3581516  .003708  .227866      .4373702 0 1 0 0
      .       .4 10 0 13 13.573532   .3141284 -.093654  .184805      .2649769 0 1 0 1
      1       .4 10 0 17 14.371478   .5781797   .00627  .624918       .354725 0 1 0 0
      2 .3636364 11 0 16  14.58138   .5433246  .008002  .771769      .4508886 0 2 0 0
      . .3333333  9 0  5  14.99727   .6372411  .046249  .675294      .6400291 0 2 1 0
      .       .3 10 0  8 15.853086   .6448011 -.028015  .562735      .6866204 0 2 1 1
      1 .3333333  9 0 14 15.853086   .6993762 -.014524  .294919     .55200505 0 1 1 1
      . .3333333  9 0  8 15.546868   .7292663  .004659 1.079276     .57907224 0 1 1 0
      . .3333333  9 0 12 15.478143   .7663349  .034199  .474701      .4666269 0 1 1 0
      .     .375  8 0  7  14.99727    .699635  .060069  .752681       .564353 0 1 1 0
      1 .3333333  9 0 10 15.620697   .6767907  .073569 1.013823      .5387814 0 1 1 0
      . .3333333  9 0  6 15.546868   .6193038  .094875  .965664      .5875554 0 1 1 0
      . .3333333  9 0  5 15.853086  .53433365  .077671  .865579     .54827505 0 1 1 0
      end
      label values OPinion OPinion
      label def OPinion 1 "0", modify
      label def OPinion 2 "1", modify
      [/CODE]

      Comment


      • #4
        the mean variable is(num_of_ac_indep)

        Comment


        • #5
          It's difficult to see from the dataset example what your identifiers are. But if I understand you correctly you have several firms over a period of time? If you want to drop those firms that never have an independent director you can try something like this:

          Code:
          bysort firm: egen independent_director_present = max(dummy_independent_director)
          This code will give a firm that never have an independen director a "0" for the the whole period they are in the sample, and "1" for firms that have an independent director at least once in your sample.

          You can then drop observations if
          Code:
           independent_director_present==0
          .

          Comment


          • #6
            Originally posted by Karl Tjensvoll View Post
            It's difficult to see from the dataset example what your identifiers are. But if I understand you correctly you have several firms over a period of time? If you want to drop those firms that never have an independent director you can try something like this:

            Code:
            bysort firm: egen independent_director_present = max(dummy_independent_director)
            This code will give a firm that never have an independen director a "0" for the the whole period they are in the sample, and "1" for firms that have an independent director at least once in your sample.

            You can then drop observations if
            Code:
             independent_director_present==0
            .
            thank you so much for relaying.
            here the correct example
            HTML Code:
            ----------------------- copy starting from the next line -----------------------
            [CODE]
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input double(code year n_of_fem_id_)
             1 2008 0
             1 2008 0
             1 2010 .
             1 2010 .
             1 2011 0
             1 2011 0
             1 2014 0
             1 2014 0
             1 2016 0
             1 2016 0
             1 2017 0
             1 2017 0
             2 2005 1
             2 2008 1
             2 2011 0
             2 2011 0
             2 2013 1
             2 2013 1
             2 2014 1
             2 2014 1
             2 2017 2
             2 2017 2
             4 2013 2
             4 2016 1
             5 2008 1
             5 2013 1
             5 2016 1
             6 2007 2
             6 2009 0
             6 2009 0
             6 2012 0
             6 2012 0
             6 2017 0
             7 2007 0
             7 2008 0
             7 2011 0
             7 2014 0
             7 2015 0
             7 2016 0
             8 2008 0
             8 2010 0
             8 2013 0
             8 2015 0
             8 2016 0
             9 2009 0
             9 2009 0
             9 2010 0
             9 2010 0
             9 2012 0
             9 2012 0
             9 2013 0
             9 2013 0
             9 2016 1
             9 2016 1
            10 2008 1
            10 2009 0
            10 2010 0
            10 2011 0
            10 2012 0
            10 2013 1
            10 2015 2
            10 2016 3
            10 2017 .
            11 2007 0
            11 2011 0
            11 2014 0
            12 2006 0
            12 2007 0
            12 2008 0
            12 2011 0
            12 2011 0
            12 2012 0
            12 2012 0
            12 2013 0
            12 2013 0
            12 2014 1
            12 2014 1
            12 2016 1
            12 2016 1
            12 2017 0
            12 2017 0
            14 2008 0
            14 2011 0
            14 2012 0
            14 2014 0
            14 2017 0
            16 2007 1
            16 2015 1
            17 2007 1
            17 2009 1
            17 2010 2
            17 2013 2
            17 2017 2
            18 2008 1
            18 2011 0
            18 2015 1
            19 2006 2
            19 2009 2
            19 2011 2
            19 2012 2
            end
            [/CODE]

            Comment


            • #7
              Karl Tjensvoll Actually i have used the code you gave but after that i cant find observations with no-independent either before or after. so do you think I have to use the variable (year) or not?
              please help

              Comment


              • #8
                Referring back to #1, it seems the result you want is
                This means that the remaining observations should consist of a firm that ( for example) did have no independent in the year 2000 then it appointed independent directors in 2001 or 2002.
                Your two example data sets cannot be matched up with each other, so we have no data set shown that contains all of year, firm identifier, and num_of_ac_indep in it. Please be more thoughtful when posting data examples in the future. The example data you post should always contain all variables that are relevant to the question you are posing.

                In any case, I have at least a partial idea of what your data look like, so I will venture a guess at code that might work for you:

                Code:
                by firm_identifier, sort: egen no_indep_2000 = max(year == 2000 & num_of_ac_indep == 0)
                by firm_identifier: egen had_indep_2001_or_2002 = max(inlist(year, 2001, 2002) & num_of_ac_indep > 0)
                gen byte wanted = no_indep_2000 & had_indep_2001_or_2002
                keep if wanted

                Comment


                • #9
                  Originally posted by Clyde Schechter View Post
                  Referring back to #1, it seems the result you want is


                  Your two example data sets cannot be matched up with each other, so we have no data set shown that contains all of year, firm identifier, and num_of_ac_indep in it. Please be more thoughtful when posting data examples in the future. The example data you post should always contain all variables that are relevant to the question you are posing.

                  In any case, I have at least a partial idea of what your data look like, so I will venture a guess at code that might work for you:

                  Code:
                  by firm_identifier, sort: egen no_indep_2000 = max(year == 2000 & num_of_ac_indep == 0)
                  by firm_identifier: egen had_indep_2001_or_2002 = max(inlist(year, 2001, 2002) & num_of_ac_indep > 0)
                  gen byte wanted = no_indep_2000 & had_indep_2001_or_2002
                  keep if wanted
                  Thank you so much. I think these commands will work.
                  my firm identifier is (code).
                  one last question:
                  if I use (max(inlist(year, 2001, 2002, 2003, 2004, 2005, 2007))). Does it work well ?

                  Comment


                  • #10
                    In your original post, you said you wanted
                    This means that the remaining observations should consist of a firm that ( for example) did have no independent in the year 2000 then it appointed independent directors in 2001 or 2002.
                    So -(max(inlist(year, 2001, 2002, 2003, 2004, 2005, 2007)))- would not produce that result. It is legal syntax, but it would leave you with firms that had no independent director in 2000 and then took one on between 2001 and 2005 or in 2007. (But not in 2006--was that intentional?) So this would include many firms that do not meet the criterion you originally stated. If you have changed your criterion, then just ask yourself if the years listed in the (max(inlist(year,....))) expression are all and only those years for which you want to retain firms that hired an independent director in that year.

                    Comment


                    • #11
                      Originally posted by Clyde Schechter View Post
                      In your original post, you said you wanted

                      So -(max(inlist(year, 2001, 2002, 2003, 2004, 2005, 2007)))- would not produce that result. It is legal syntax, but it would leave you with firms that had no independent director in 2000 and then took one on between 2001 and 2005 or in 2007. (But not in 2006--was that intentional?) So this would include many firms that do not meet the criterion you originally stated. If you have changed your criterion, then just ask yourself if the years listed in the (max(inlist(year,....))) expression are all and only those years for which you want to retain firms that hired an independent director in that year.
                      Yes yes you are right regarding my statement in the first place.
                      but I am also gonna Extend the period till 2007, mistakenly I missed the 2006.
                      However, my question is: if I use the command keep then all firms that have no independent directors will be deleted, so how can I compare. Also, if I don’t delete them I will compare between all firms with independent and non-independent directors. Means I can not fulfill what I want.
                      so, my objective is to keep firms that have independent directors but before and after hiring independent directors. Which suggests that I can create dummy variable that coded 1 after hiring, zero before.
                      in sum, like create the post variable in applying Differences-in-Difference technique.
                      where I claim in my hypothesis that hiring independent directors improve the firm performance. The referees asked me to apply the DiD as robustness test.
                      so I tried to get help creating a post variable.
                      Sorry for confusing you.
                      kindly if you could help in performing the DiD I will be grateful thanks

                      Comment


                      • #12
                        If you want to create a pre-post variable, it would be this:

                        Code:
                        assert !missing(num_ac_indep) & num_ac_indep >= 0
                        by firm_identifier (year), sort: gen pre_post = sum(num_ac_indep > 0)
                        replace num_ac_indep = min(num_ac_indep, 1)
                        You won't remove any observations with this code, nor should you if your goal is to do a DID regression.

                        If you need additional help performing the DID regression, please start a new thread. It is important to keep threads on topic so that people who come searching for specific things can find what they are looking for and don't waste their time reading thing that are irrelevant. If you do that, include a fresh data example that includes all the variables that you will need to include in your DID analysis and includes several firms that do transition between having and not having independent directors.

                        Comment


                        • #13
                          Originally posted by Clyde Schechter View Post
                          If you want to create a pre-post variable, it would be this:

                          Code:
                          assert !missing(num_ac_indep) & num_ac_indep >= 0
                          by firm_identifier (year), sort: gen pre_post = sum(num_ac_indep > 0)
                          replace num_ac_indep = min(num_ac_indep, 1)
                          You won't remove any observations with this code, nor should you if your goal is to do a DID regression.

                          If you need additional help performing the DID regression, please start a new thread. It is important to keep threads on topic so that people who come searching for specific things can find what they are looking for and don't waste their time reading thing that are irrelevant. If you do that, include a fresh data example that includes all the variables that you will need to include in your DID analysis and includes several firms that do transition between having and not having independent directors.
                          Clyde Schechter thank you so much.
                          I will create new topic and explain my needs in detail.
                          I will try using the commands you have given as well.
                          once again thank you so much

                          Comment

                          Working...
                          X