Announcement

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

  • No change in a variable for at least two consecutive years

    Dear Stata Experts,
    I wish to create a dummy variable to capture a situation where the variable co-option does not change in at least two consecutive years. the data is given below for your reference. Please guide me for this estimation.


    Thank you so much

    dataex gvkey fyear co-option

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(gvkey fyear) float co-option
    1004 1996         1
    1004 1997         0
    1004 1998         0
    1004 1999         0
    1004 2000         0
    1004 2001       .25
    1004 2002  .3333333
    1004 2003        .5
    1004 2004      .625
    1004 2005  .8571429
    1004 2006  .8888889
    1004 2007  .9090909
    1013 1996        .3
    1013 1997  .3636364
    1013 1998  .3636364
    1013 1999  .3333333
    1013 2000        .7
    1013 2001      .625
    1013 2002        .3
    1013 2003  .3636364
    1013 2004         0
    1013 2005  .3076923
    1013 2006  .3333333
    1013 2007        .4
    1013 2008        .4
    1034 1997         0
    1034 1998 .22222222
    1034 1999 .22222222
    1034 2000 .11111111
    1034 2001 .11111111
    1034 2002        .3
    1034 2003  .6666667
    1034 2004  .6666667
    1034 2005        .7
    1034 2006        .5
    1034 2007        .5
    1045 1996        .7
    1045 1997        .7
    1045 1998       .75
    1045 1999  .0909091
    1045 2000        .2
    1045 2001        .3
    1045 2002  .4166667
    1072 2000        .5
    1072 2001        .5
    1078 1996  .1818182
    1078 1997        .2
    1078 1998     .4375
    1078 1999 .07692308
    1078 2000 .08333334
    1078 2001 .23076923
    1078 2002  .2857143
    1078 2003  .3076923
    1078 2004  .3076923
    1078 2005  .3571429
    1078 2006  .3846154
    1078 2007  .4615385
    1078 2008  .4615385
    1111 2003         1
    1111 2004         1
    1111 2005         1
    1111 2006         1
    1111 2007         1
    1115 1996        .2
    1115 1997  .3333333
    1115 1998         0
    1115 1999 .14285715
    1164 1996      .625
    1164 1997  .6666667
    1164 1998  .7272727
    1164 1999  .8235294
    1164 2000  .7857143
    1164 2001       .75
    1203 1996      .375
    1203 1997      .375
    1203 1998      .375
    1209 1996  .5555556
    1209 1997  .6363636
    1209 1998  .6666667
    1209 1999  .7692308
    1209 2000  .7692308
    1209 2001  .9090909
    1209 2002  .1818182
    1209 2003 .27272728
    1209 2004        .4
    1209 2005 .54545456
    1209 2006 .54545456
    1209 2007      .625
    1209 2008         0
    1213 1996      .625
    1213 1997  .6666667
    1213 1998  .6666667
    1213 1999  .6666667
    1213 2000  .6666667
    1213 2001        .7
    1213 2002      .875
    1230 1996         0
    1230 1997 .11111111
    1230 1998 .11111111
    1230 1999 .22222222
    end

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(gvkey fyear) float co_option
    1004 1996         1
    1004 1997         0
    1004 1998         0
    1004 1999         0
    1004 2000         0
    1004 2001       .25
    1004 2002  .3333333
    1004 2003        .5
    1004 2004      .625
    1004 2005  .8571429
    1004 2006  .8888889
    1004 2007  .9090909
    1013 1996        .3
    1013 1997  .3636364
    1013 1998  .3636364
    1013 1999  .3333333
    1013 2000        .7
    1013 2001      .625
    1013 2002        .3
    1013 2003  .3636364
    1013 2004         0
    1013 2005  .3076923
    1013 2006  .3333333
    1013 2007        .4
    1013 2008        .4
    1034 1997         0
    1034 1998 .22222222
    1034 1999 .22222222
    1034 2000 .11111111
    1034 2001 .11111111
    1034 2002        .3
    1034 2003  .6666667
    1034 2004  .6666667
    1034 2005        .7
    1034 2006        .5
    1034 2007        .5
    1045 1996        .7
    1045 1997        .7
    1045 1998       .75
    1045 1999  .0909091
    1045 2000        .2
    1045 2001        .3
    1045 2002  .4166667
    1072 2000        .5
    1072 2001        .5
    1078 1996  .1818182
    1078 1997        .2
    1078 1998     .4375
    1078 1999 .07692308
    1078 2000 .08333334
    1078 2001 .23076923
    1078 2002  .2857143
    1078 2003  .3076923
    1078 2004  .3076923
    1078 2005  .3571429
    1078 2006  .3846154
    1078 2007  .4615385
    1078 2008  .4615385
    1111 2003         1
    1111 2004         1
    1111 2005         1
    1111 2006         1
    1111 2007         1
    1115 1996        .2
    1115 1997  .3333333
    1115 1998         0
    1115 1999 .14285715
    1164 1996      .625
    1164 1997  .6666667
    1164 1998  .7272727
    1164 1999  .8235294
    1164 2000  .7857143
    1164 2001       .75
    1203 1996      .375
    1203 1997      .375
    1203 1998      .375
    1209 1996  .5555556
    1209 1997  .6363636
    1209 1998  .6666667
    1209 1999  .7692308
    1209 2000  .7692308
    1209 2001  .9090909
    1209 2002  .1818182
    1209 2003 .27272728
    1209 2004        .4
    1209 2005 .54545456
    1209 2006 .54545456
    1209 2007      .625
    1209 2008         0
    1213 1996      .625
    1213 1997  .6666667
    1213 1998  .6666667
    1213 1999  .6666667
    1213 2000  .6666667
    1213 2001        .7
    1213 2002      .875
    1230 1996         0
    1230 1997 .11111111
    1230 1998 .11111111
    1230 1999 .22222222
    end
    
    bys gvkey (fyear): gen n = sum(co_option!=co_option[_n-1])
    bys gvkey n: gen wanted = _N >= 3
    drop n

    Comment


    • #3
      Miral:
      a less efficient option might be:
      Code:
      . bysort gvkey (fyear): gen wanted=1 if co_option[_n]==co_option[_n+1]
      . bysort gvkey (fyear): gen wanted2=1 if co_option[_n-1]==co_option[_n]
      . gen wanted3=wanted
      . replace wanted3=wanted2 if wanted==. & wanted2!=.
      . drop wanted wanted2
      . rename wanted3 wanted
      . list gvkey fyear co_option wanted3 if gvkey==1004
      
           +------------------------------------+
           | gvkey   fyear   co_opt~n   wanted3 |
           |------------------------------------|
        1. |  1004    1996          1         . |
        2. |  1004    1997          0         1 |
        3. |  1004    1998          0         1 |
        4. |  1004    1999          0         1 |
        5. |  1004    2000          0         1 |
           |------------------------------------|
        6. |  1004    2001        .25         . |
        7. |  1004    2002   .3333333         . |
        8. |  1004    2003         .5         . |
        9. |  1004    2004       .625         . |
       10. |  1004    2005   .8571429         . |
           |------------------------------------|
       11. |  1004    2006   .8888889         . |
       12. |  1004    2007   .9090909         . |
           +------------------------------------+
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Dear @Fei Wang:
        Thank you so much for the code. Really appreciate that !!!

        Comment


        • #5
          Dear Carlo Lazzaro ,
          Thanks. The code is really helpful. You have made things easier for my thesis.

          Comment


          • #6
            Miral:
            happy to be of some help.
            That said, please note that
            Code:
            co-option
            is not a legal name for Stata, whereas
            Code:
            co_option 
            works.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Dear Carlo Lazzaro , May I further ask another question? :
              I need to measure changes in board co-option around an exogenous event, EVENT. I want to create a treatment group that increases cooption and control that decreases the cooption a year following the EVENT. May I request if you could help me on this code?
              Thanks in advance !!!

              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input long gvkey double(fyear CEO_ID) float cooption byte EVENT
              1004 1996 5623 1 .
              1004 1997 5623 0 .
              1004 1998 5623 0 .
              1004 1999 5623 0 .
              1004 2000 5623 0 .
              1004 2001 5623 .25 .
              1004 2002 5623 .3333333 .
              1004 2003 5623 .5 .
              1004 2004 5623 .625 .
              1004 2005 5623 .8571429 .
              1004 2006 5623 .8888889 .
              1004 2007 5623 .9090909 .
              1004 2008 5623 .9090909 .
              1004 2009 5623 .9090909 .
              1004 2010 5623 .9 .
              1004 2011 5623 .9090909 .
              1004 2012 5623 .9090909 .
              1004 2013 5623 .9090909 .
              1004 2014 5623 .9090909 .
              1004 2015 5623 .9090909 .
              1013 1996 2611 .3 .
              1013 1997 2611 .3636364 .
              1013 1998 2611 .3636364 .
              1013 1999 2611 .3333333 .
              1013 2000 2611 .7 .
              1013 2001 23275 .625 1
              1013 2002 23275 .3 .
              1013 2003 23275 .3636364 .
              1013 2004 8741 0 .
              1013 2005 8741 .3076923 .
              1013 2006 8741 .3333333 .
              1013 2007 8741 .4 .
              1013 2008 8741 .4 .
              1013 2009 8741 .5 .
              1034 1997 5627 0 .
              1034 1998 5627 .22222222 .
              1034 1999 16765 .22222222 .
              1034 2000 9410 .11111111 .
              1034 2001 9410 .11111111 .
              1034 2002 9410 .3 .
              1034 2003 9410 .6666667 .
              1034 2004 9410 .6666667 .
              1034 2005 9410 .7 .
              1034 2006 33287 .5 .
              1034 2007 33287 .5 .
              1045 1996 1 .7 .
              1045 1997 1 .7 .
              1045 1998 3 .75 .
              1045 1999 3 .0909091 .
              1045 2000 3 .2 .
              1045 2001 3 .3 .
              1045 2002 3 .4166667 .
              1045 2015 49256 0 .
              1072 2000 23603 .5 .
              1072 2001 23604 .5 .
              1078 1996 6 .1818182 .
              1078 1997 6 .2 .
              1078 1998 6 .4375 .
              1078 1999 13896 .07692308 1
              1078 2000 13896 .08333334 .
              1078 2001 13896 .23076923 .
              1078 2002 13896 .2857143 .
              1078 2003 13896 .3076923 .
              1078 2004 13896 .3076923 .
              1078 2005 13896 .3571429 .
              1078 2006 13896 .3846154 .
              1078 2007 13896 .4615385 .
              1078 2008 13896 .4615385 .
              1078 2009 13896 .53846157 .
              1078 2010 13896 .5833333 .
              1078 2011 13896 .8 .
              1078 2012 13896 .9090909 .
              1078 2013 13896 .9090909 .
              1078 2014 13896 .9090909 .
              1078 2015 13896 .9090909 .
              1111 2003 23381 1 .
              1111 2004 23381 1 .
              1111 2005 23381 1 .
              1111 2006 23381 1 .
              1111 2007 23381 1 .
              1115 1996 5633 .2 .
              1115 1997 5633 .3333333 .
              1115 1998 5634 0 .
              1115 1999 5634 .14285715 .
              1161 2000 . . .
              1161 2001 . . .
              1161 2002 . . .
              1161 2003 . . .
              1161 2004 . . .
              1164 1996 2627 .625 .
              1164 1997 2627 .6666667 .
              1164 1998 2627 .7272727 .
              1164 1999 2627 .8235294 .
              1164 2000 2627 .7857143 .
              1164 2001 2627 .75 .
              1203 1996 8753 .375 .
              1203 1997 8753 .375 .
              1203 1998 8753 .375 .
              1209 1996 28 .5555556 .
              1209 1997 28 .6363636 .
              end
              [/CODE]
              ------------------ copy up to and including the previous line ------------------


              ​​​​​​​

              Comment


              • #8
                Is a year with an EVENT one with

                Code:
                EVENT == 1 
                
                EVENT > 0
                or something else?

                Comment


                • #9
                  Dear Nick Cox. Thanks for your reply. If I understand correctly, The Event is a dummy variable that equals 1 if a certain event happened, and 0 otherwise.

                  Please correct me if I am not getting it.

                  Thank you

                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input long gvkey double fyear float cooption double CEO_ID float EVENT
                  1004 1996 1 5623 0
                  1004 1997 0 5623 0
                  1004 1998 0 5623 0
                  1004 1999 0 5623 0
                  1004 2000 0 5623 0
                  1004 2001 .25 5623 0
                  1004 2002 .3333333 5623 0
                  1004 2003 .5 5623 0
                  1004 2004 .625 5623 0
                  1004 2005 .8571429 5623 0
                  1004 2006 .8888889 5623 0
                  1004 2007 .9090909 5623 0
                  1004 2008 .9090909 5623 0
                  1004 2009 .9090909 5623 0
                  1004 2010 .9 5623 0
                  1004 2011 .9090909 5623 0
                  1004 2012 .9090909 5623 0
                  1004 2013 .9090909 5623 0
                  1004 2014 .9090909 5623 0
                  1004 2015 .9090909 5623 0
                  1013 1996 .3 2611 0
                  1013 1997 .3636364 2611 0
                  1013 1998 .3636364 2611 0
                  1013 1999 .3333333 2611 0
                  1013 2000 .7 2611 0
                  1013 2001 .625 23275 1
                  1013 2002 .3 23275 0
                  1013 2003 .3636364 23275 0
                  1013 2004 0 8741 0
                  1013 2005 .3076923 8741 0
                  1013 2006 .3333333 8741 0
                  1013 2007 .4 8741 0
                  1013 2008 .4 8741 0
                  1013 2009 .5 8741 0
                  1034 1997 0 5627 0
                  1034 1998 .22222222 5627 0
                  1034 1999 .22222222 16765 0
                  1034 2000 .11111111 9410 0
                  1034 2001 .11111111 9410 0
                  1034 2002 .3 9410 0
                  1034 2003 .6666667 9410 0
                  1034 2004 .6666667 9410 0
                  1034 2005 .7 9410 0
                  1034 2006 .5 33287 0
                  1034 2007 .5 33287 0
                  1045 1996 .7 1 0
                  1045 1997 .7 1 0
                  1045 1998 .75 3 0
                  1045 1999 .0909091 3 0
                  1045 2000 .2 3 0
                  1045 2001 .3 3 0
                  1045 2002 .4166667 3 0
                  1045 2015 0 49256 0
                  1072 2000 .5 23603 0
                  1072 2001 .5 23604 0
                  1078 1996 .1818182 6 0
                  1078 1997 .2 6 0
                  1078 1998 .4375 6 0
                  1078 1999 .07692308 13896 1
                  1078 2000 .08333334 13896 0
                  1078 2001 .23076923 13896 0
                  1078 2002 .2857143 13896 0
                  1078 2003 .3076923 13896 0
                  1078 2004 .3076923 13896 0
                  1078 2005 .3571429 13896 0
                  1078 2006 .3846154 13896 0
                  1078 2007 .4615385 13896 0
                  1078 2008 .4615385 13896 0
                  1078 2009 .53846157 13896 0
                  1078 2010 .5833333 13896 0
                  1078 2011 .8 13896 0
                  1078 2012 .9090909 13896 0
                  1078 2013 .9090909 13896 0
                  1078 2014 .9090909 13896 0
                  1078 2015 .9090909 13896 0
                  1111 2003 1 23381 0
                  1111 2004 1 23381 0
                  1111 2005 1 23381 0
                  1111 2006 1 23381 0
                  1111 2007 1 23381 0
                  1115 1996 .2 5633 0
                  1115 1997 .3333333 5633 0
                  1115 1998 0 5634 0
                  1115 1999 .14285715 5634 0
                  1161 2000 . . 0
                  1161 2001 . . 0
                  1161 2002 . . 0
                  1161 2003 . . 0
                  1161 2004 . . 0
                  1164 1996 .625 2627 0
                  1164 1997 .6666667 2627 0
                  1164 1998 .7272727 2627 0
                  1164 1999 .8235294 2627 0
                  1164 2000 .7857143 2627 0
                  1164 2001 .75 2627 0
                  1203 1996 .375 8753 0
                  1203 1997 .375 8753 0
                  1203 1998 .375 8753 0
                  1209 1996 .5555556 28 0
                  1209 1997 .6363636 28 0
                  end
                  [/CODE]
                  ------------------ copy up to a

                  Comment


                  • #10
                    Miral:
                    what I'm not clear with your query is the following statement:
                    ...I want to create a treatment group that increases cooption and control that decreases the cooption a year following the EVENT.
                    What does it mean? Thanks.
                    Kind regards,
                    Carlo
                    (Stata 19.0)

                    Comment


                    • #11
                      Dear Carlo Lazzaro, I am sorry for not the confusion. Below is what I meant:
                      "I want to create a treatment group consisting of firms that have experienced an increase in their co-opted board ratios (cooption) a year following the sudden death of a CEO (EVENT). We also create a control group, which includes firms that have experienced a reduction in their co-opted board ratios (cooption) in the same year."

                      Thank you so much for your guidance !!!

                      Comment


                      • #12
                        Miral:
                        if I get you right, you may want to try something along the following lines:
                        Code:
                        . bysort gvkey ( fyear ): g sum_cooption=sum( cooption)
                        
                        . bysort gvkey ( fyear ): g wanted_1=1 if EVENT==1 & cooption[_n]<cooption[_n-1]
                        
                        . bysort gvkey ( fyear ): g wanted_2=1 if EVENT==1 & cooption[_n]>cooption[_n-1]
                        Kind regards,
                        Carlo
                        (Stata 19.0)

                        Comment

                        Working...
                        X