Announcement

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

  • Creating Variable and Dummy Variable Based on Condition Met in Each Year

    I am trying to create dummy variable based on conditions met in each the year - I will have two variables one is "Compliance 1" and "Compliance 2". I have tried looking into several forum posts and elsewhere but could't come up with the code to match my requirement

    - The condition of Compliance 1 will include ONLY firms/tickers that has independent directors (INBD) greater than or equal to 3 is each year for the entire sample period
    - The condition of Compliance 2 will include firms that has independent directors (INBD) greater or equal to 3 in any year after 1999 - but will exclude firms not included in COMPLIANCE 1

    Later, I plan to use these two variables to create the dummy variable. The reason I am doing this to do t-test to test the significance in means for each group

    Any help would or clue towards establishing this would be great. Thank you in advance


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str9 Ticker int Year byte INBD
    "TH:2S"     1995 4
    "TH:2S"     1996 2
    "TH:2S"     1997 4
    "TH:2S"     1998 3
    "TH:2S"     1999 5
    "TH:2S"     2000 4
    "TH:2S"     2001 3
    "TH:2S"     2002 3
    "TH:2S"     2003 3
    "TH:A"      1995 5
    "TH:A"      1996 5
    "TH:A"      1997 0
    "TH:A"      1998 3
    "TH:A"      1999 2
    "TH:A"      2000 4
    "TH:A"      2001 8
    "TH:A"      2002 3
    "TH:A"      2003 4
    "TH:AA"     1995 5
    "TH:AA"     1996 0
    "TH:AA"     1997 3
    "TH:AA"     1998 5
    "TH:AA"     1999 3
    "TH:AA"     2000 7
    "TH:AA"     2001 2
    "TH:AA"     2002 5
    "TH:AA"     2003 6
    "TH:AAV"    1995 3
    "TH:AAV"    1996 3
    "TH:AAV"    1997 4
    "TH:AAV"    1998 0
    "TH:AAV"    1999 0
    "TH:AAV"    2000 7
    "TH:AAV"    2001 0
    "TH:AAV"    2002 3
    "TH:AAV"    2003 0
    "TH:ABICO"  1995 4
    "TH:ABICO"  1996 4
    "TH:ABICO"  1997 3
    "TH:ABICO"  1998 4
    "TH:ABICO"  1999 3
    "TH:ABICO"  2000 1
    "TH:ABICO"  2001 3
    "TH:ABICO"  2002 4
    "TH:ABICO"  2003 0
    "TH:ACC"    1995 3
    "TH:ACC"    1996 3
    "TH:ACC"    1997 2
    "TH:ACC"    1998 3
    "TH:ACC"    1999 3
    "TH:ACC"    2000 0
    "TH:ACC"    2001 4
    "TH:ACC"    2002 4
    "TH:ACC"    2003 1
    "TH:ADVANC" 1995 3
    "TH:ADVANC" 1996 4
    "TH:ADVANC" 1997 4
    "TH:ADVANC" 1998 4
    "TH:ADVANC" 1999 0
    "TH:ADVANC" 2000 0
    "TH:ADVANC" 2001 2
    "TH:ADVANC" 2002 3
    "TH:ADVANC" 2003 3
    "TH:AFC"    1995 3
    "TH:AFC"    1996 0
    "TH:AFC"    1997 3
    "TH:AFC"    1998 2
    "TH:AFC"    1999 3
    "TH:AFC"    2000 1
    "TH:AFC"    2001 4
    "TH:AFC"    2002 3
    "TH:AFC"    2003 2
    "TH:AGE"    1995 0
    "TH:AGE"    1996 2
    "TH:AGE"    1997 0
    "TH:AGE"    1998 2
    "TH:AGE"    1999 3
    "TH:AGE"    2000 4
    "TH:AGE"    2001 3
    "TH:AGE"    2002 5
    "TH:AGE"    2003 3
    "TH:AH"     1995 3
    "TH:AH"     1996 4
    "TH:AH"     1997 7
    "TH:AH"     1998 4
    "TH:AH"     1999 0
    "TH:AH"     2000 3
    "TH:AH"     2001 2
    "TH:AH"     2002 2
    "TH:AH"     2003 3
    "TH:AHC"    1995 4
    "TH:AHC"    1996 3
    "TH:AHC"    1997 2
    "TH:AHC"    1998 4
    "TH:AHC"    1999 4
    "TH:AHC"    2000 0
    "TH:AHC"    2001 4
    "TH:AHC"    2002 2
    "TH:AHC"    2003 4
    "TH:AI"     1995 2
    end
    format %ty Year
    Last edited by Farhan Hasnat; 03 Jun 2022, 14:52.

  • #2
    I'm not sure I understand what you are asking for, because I cannot make any sense of "but will exclude firms not included in COMPLIANCE 1." After all, if compliance_1 == 1, then INBD >= 3 in every year, so it will be true at least once after 1999 unless the firm (like TH:AI) has no data after 1999 at all. So this makes me think I am misunderstanding something.

    Anyway, I have just ignored the "but will exclude...." condition and come up with the following commands:
    Code:
    by Ticker (Year), sort: egen byte compliance_1 = min(INBD >= 3)
    
    by Ticker (Year): egen byte compliance_2 = max((INBD >= 3) & (Year > 1999))
    Note: In your example data, no firm meets the criterion for compliance_1.

    If these are not what you want, please post back with a clearer explanation. It would probably also help to include some worked-out examples, or some specific examples where this code produces incorrect results and why..

    Comment


    • #3
      Clyde Schechter Thank you Clyde for your helpful advice. Sorry I probably should have been more clear on my first post. The commands that you have suggested is exactly what I want - however, the only tweak is -

      Although using -dataex- I show portion of my sample, but there are some firms in my full sample period that has 3 INBD is all years -

      Answering: "but will exclude firms not included in COMPLIANCE 1." - So the firms that has 3 INBD for the entire sample period in this case 1995-2003 - Should not be included in the compliance 2 as they are in compliance anyway. Reiterating my argument - Compliance 2 are firms that met the regulatory rule of having 3 INBD after year 1999 so excluding firms that are in Compliance 1 sort of show "good" firms that always were in compliance.

      This commands does exactly what I want

      Code:
      by Ticker (Year), sort: egen byte compliance_1 = min(INBD >= 3)
      I believe the second command needs an argument asking the program to ignore all the "ticker/firms" that are included in "compliance_1"

      Code:
      by Ticker (Year): egen byte compliance_2 = max((INBD >= 3) & (Year > 1999))
      I have edited the data provided earlier -dataex- to give the gist of it. For Ticker "TH:2S/TH:A/TH:AA" the data is edited such that the firm has minimum of 3 INBD is all years (Compliance_1) firm; in contrast ticker "TH:AAV" is edited such that the firm has minimum of 3 INBD after year 1999. So tickers "TH:2S/TH:A/TH:AA" should not be included in the Compliance 2 but only in compliance 1 and ticker "TH:AAV" should only be included in the compliance 2 grouping.

      Thank you once again for your helpful advice.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str9 Ticker int Year byte INDEP_Directors
      "TH:2S"     1995 4
      "TH:2S"     1996 3
      "TH:2S"     1997 4
      "TH:2S"     1998 3
      "TH:2S"     1999 5
      "TH:2S"     2000 4
      "TH:2S"     2001 3
      "TH:2S"     2002 3
      "TH:2S"     2003 3
      "TH:A"      1995 5
      "TH:A"      1996 5
      "TH:A"      1997 3
      "TH:A"      1998 3
      "TH:A"      1999 3
      "TH:A"      2000 4
      "TH:A"      2001 8
      "TH:A"      2002 3
      "TH:A"      2003 4
      "TH:AA"     1995 5
      "TH:AA"     1996 3
      "TH:AA"     1997 3
      "TH:AA"     1998 5
      "TH:AA"     1999 3
      "TH:AA"     2000 7
      "TH:AA"     2001 3
      "TH:AA"     2002 5
      "TH:AA"     2003 6
      "TH:AAV"    1995 3
      "TH:AAV"    1996 3
      "TH:AAV"    1997 4
      "TH:AAV"    1998 0
      "TH:AAV"    1999 0
      "TH:AAV"    2000 7
      "TH:AAV"    2001 3
      "TH:AAV"    2002 3
      "TH:AAV"    2003 3
      "TH:ABICO"  1995 4
      "TH:ABICO"  1996 4
      "TH:ABICO"  1997 3
      "TH:ABICO"  1998 4
      "TH:ABICO"  1999 3
      "TH:ABICO"  2000 1
      "TH:ABICO"  2001 3
      "TH:ABICO"  2002 4
      "TH:ABICO"  2003 0
      "TH:ACC"    1995 3
      "TH:ACC"    1996 3
      "TH:ACC"    1997 2
      "TH:ACC"    1998 3
      "TH:ACC"    1999 3
      "TH:ACC"    2000 0
      "TH:ACC"    2001 4
      "TH:ACC"    2002 4
      "TH:ACC"    2003 1
      "TH:ADVANC" 1995 3
      "TH:ADVANC" 1996 4
      "TH:ADVANC" 1997 4
      "TH:ADVANC" 1998 4
      "TH:ADVANC" 1999 0
      "TH:ADVANC" 2000 0
      "TH:ADVANC" 2001 2
      "TH:ADVANC" 2002 3
      "TH:ADVANC" 2003 3
      "TH:AFC"    1995 3
      "TH:AFC"    1996 0
      "TH:AFC"    1997 3
      "TH:AFC"    1998 2
      "TH:AFC"    1999 3
      "TH:AFC"    2000 1
      "TH:AFC"    2001 4
      "TH:AFC"    2002 3
      "TH:AFC"    2003 2
      "TH:AGE"    1995 0
      "TH:AGE"    1996 2
      "TH:AGE"    1997 0
      "TH:AGE"    1998 2
      "TH:AGE"    1999 3
      "TH:AGE"    2000 4
      "TH:AGE"    2001 3
      "TH:AGE"    2002 5
      "TH:AGE"    2003 3
      "TH:AH"     1995 3
      "TH:AH"     1996 4
      "TH:AH"     1997 7
      "TH:AH"     1998 4
      "TH:AH"     1999 0
      "TH:AH"     2000 3
      "TH:AH"     2001 2
      "TH:AH"     2002 2
      "TH:AH"     2003 3
      "TH:AHC"    1995 4
      "TH:AHC"    1996 3
      "TH:AHC"    1997 2
      "TH:AHC"    1998 4
      "TH:AHC"    1999 4
      "TH:AHC"    2000 0
      "TH:AHC"    2001 4
      "TH:AHC"    2002 2
      "TH:AHC"    2003 4
      "TH:AI"     1995 2
      end
      format %ty Year
      Last edited by Farhan Hasnat; 04 Jun 2022, 03:07.

      Comment


      • #4
        I see. Well, there is still a bit of remaining ambiguity in "exclude firms not included in COMPLIANCE 1." I can think of two ways to handle this. One is to set compliance_2 to missing value when compliance_1 == 1. That is, compliance_2 simply is not applicable to those already meeting compliance_1. The other possibility is to set compliance_2 = 0 when compliance_1 == 1. The following code shows you both possibilities. The first is called compliance_2a and the second is called compliance_2b. Pick whichever is more suitable for your purposes.

        Code:
        by Ticker (Year), sort: egen byte compliance_1 = min(INDEP_Directors >= 3)
        
        by Ticker (Year): egen byte compliance_2a = max((INDEP_Directors >= 3) & (Year > 1999)) ///
            if !compliance_1
            
        by Ticker (Year): egen byte compliance_2b = max((INDEP_Directors >= 3)  ///
            & (Year > 1999) & !compliance_1)

        Comment


        • #5
          Clyde Schechter Thank you and much appreciated your help on this. This gets me to exactly how I wanted it to be.

          Comment

          Working...
          X