Announcement

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

  • Calculating dummies based on other variables

    Dear specialists,

    I have a panel data, it includes Stock ID (Stkcd), fiscal year (Year), Background of members (Funback) which includes directors and CEO, age of members (Age) and academic degree (Degree). The other two variables are dummies if they are directors (Indep) or CEO (isCEO).


    Based on the panel data below, may you aid me to calculate the following variables?

    1) I want to calculate a variable V1= is a dummy variable equals 1 if Funback of Indep includes any value of isCEO. For example, if isCEO contains 7,8,5 and Indep includes 8, V1=1
    2) I want to calculate a variable V2= is a dummy variable equals 1 if Degree of Indep is the same as isCEO.
    3) I want to calculate a variable V3= is a dummy variable equals 1 if Age of Indep is within 10 years of isCEO. In other words If the difference between the age of an Indep and the age of isCEO is within 10 years, the value is 1, otherwise the value is 0.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 Stkcd int Year str23 Funback str7(Age Degree) float(isCEO Indep)
    "000001" 2011 "7"         "55" "4" 0 0
    "000001" 2011 "7"         "55" "3" 0 0
    "000001" 2011 "7,8"       "40" "4" 0 0
    "000001" 2011 "7,8,2"     "47" "5" 0 1
    "000001" 2011 "7"         "55" ""  1 0
    "000001" 2011 "7,2"       "64" "4" 0 1
    "000001" 2011 "7,5"       "58" "3" 0 1
    "000001" 2011 "5,7"       "37" "3" 0 0
    "000001" 2011 "7,5"       "62" "5" 0 1
    "000001" 2011 "7,9"       "47" "4" 0 1
    "000001" 2011 "4,7,8"     "49" "4" 0 0
    "000001" 2011 "7,4,5"     "62" "3" 0 1
    "000001" 2011 "7,8,5"     "50" "5" 0 1
    "000001" 2011 "7,5"       "56" "4" 0 0
    "000001" 2011 "7,5"       "53" "5" 0 0
    "000001" 2011 "7,8,5"     "52" "5" 0 0
    "000001" 2011 "2,4,5,7,8" "63" "2" 0 0
    "000001" 2011 "7,5"       "60" "5" 0 1
    "000001" 2012 "7,8,5"     "53" "5" 0 0
    "000001" 2012 "7,8"       "41" "4" 0 0
    "000001" 2012 "4,7,8"     "50" "4" 0 0
    "000001" 2012 "7"         "56" "4" 0 0
    "000001" 2012 "7,9"       "48" "4" 0 1
    "000001" 2012 "7,5"       "61" "5" 0 1
    "000001" 2012 "7,4,5"     "63" "3" 0 1
    "000001" 2012 "7,5"       "54" "5" 0 0
    "000001" 2012 "7,8,5"     "51" "5" 0 1
    "000001" 2012 "7,5"       "59" "2" 0 0
    "000001" 2012 "7,5"       "63" "5" 0 1
    "000001" 2012 "7,5"       "59" "3" 0 1
    "000001" 2012 "7"         "55" "5" 1 0
    "000001" 2012 "2,7,8"     "48" "5" 0 1
    "000001" 2012 "5,7"       "38" "3" 0 0
    "000001" 2012 "7"         "56" "3" 0 0
    "000001" 2012 "7,2"       "65" "4" 0 1
    "000001" 2012 "7,5"       "57" "4" 0 0
    "000001" 2013 "7,5"       "55" "5" 0 0
    "000001" 2013 "5,7"       "58" "4" 0 0
    "000001" 2013 "7"         "57" "3" 0 0
    "000001" 2013 "7"         "57" "4" 0 0
    "000001" 2013 "7,8,5"     "54" "5" 0 0
    "000001" 2013 "7,5"       "60" "3" 0 1
    "000001" 2013 "7,2"       "66" "4" 0 1
    "000001" 2013 "7,5"       "64" "5" 0 1
    "000001" 2013 "7"         "56" "5" 1 0
    "000001" 2013 "5,7"       "39" "3" 0 0
    "000001" 2013 "2,7,8"     "49" "5" 0 1
    "000001" 2013 "7,8"       "42" "4" 0 0
    "000001" 2013 "7,9"       "49" "4" 0 1
    "000001" 2013 "4,7,8"     "51" "4" 0 0
    "000001" 2013 "7,5"       "60" "2" 0 0
    "000001" 2013 "7,5"       "62" "5" 0 1
    "000001" 2013 "7,8,5"     "52" "5" 0 1
    "000001" 2013 "7,4,5"     "64" "3" 0 1
    "000001" 2014 "5,7"       "63" "2" 0 1
    "000001" 2014 "5,7,8"     "55" "5" 0 0
    "000001" 2014 "5,7"       "61" "2" 0 0
    "000001" 2014 "5,7"       "61" "3" 0 1
    "000001" 2014 "7,9"       "59" "4" 0 1
    "000001" 2014 "5,7,8"     "43" "4" 0 0
    "000001" 2014 "5,7,8"     "58" "3" 0 0
    "000001" 2014 "5,6,7"     "59" "4" 0 0
    "000001" 2014 "2,5,7,8"   "50" "5" 0 1
    "000001" 2014 "5,7"       "57" "5" 1 0
    "000001" 2014 "5,6,7"     "51" "4" 0 0
    "000001" 2014 "5,7"       "37" "4" 0 0
    "000001" 2014 "2,7"       "62" "5" 0 1
    "000001" 2014 "4,5,7,8"   "52" "4" 0 0
    "000001" 2014 "4,5,7"     "40" "4" 0 0
    "000001" 2015 "5,7,8"     "44" "4" 0 0
    "000001" 2015 "5,7"       "58" "5" 1 0
    "000001" 2015 "4,5,7,8"   "41" "4" 0 0
    "000001" 2015 "5,7"       "62" "2" 0 0
    "000001" 2015 "5,6,7"     "52" "5" 0 0
    "000001" 2015 "4,5,6,7,8" "53" "4" 0 0
    "000001" 2015 "5,7,8"     "59" "3" 0 0
    "000001" 2015 "5,7"       "38" "4" 0 0
    "000001" 2015 "5,6,7"     "60" "4" 0 0
    "000001" 2015 "7,9"       "60" "4" 0 1
    "000001" 2015 "2,5,7,8"   "51" "5" 0 1
    "000001" 2015 "5,7"       "62" "3" 0 1
    "000001" 2015 "2,7"       "63" "5" 0 1
    "000001" 2015 "5,7,8"     "64" "2" 0 1
    "000001" 2016 "2,5,7"     "64" "5" 0 1
    "000001" 2016 "5,7,8"     "45" "4" 0 0
    "000001" 2016 "5,7"       "39" "4" 0 0
    "000001" 2016 "5,7,8"     "65" "2" 0 1
    "000001" 2016 "7"         "48" "5" 0 1
    "000001" 2016 "4,5,6,7"   "48" "5" 0 0
    "000001" 2016 "4,5,7,8"   "42" "4" 0 0
    "000001" 2016 "7,9"       "61" "4" 0 1
    "000001" 2016 "5,7,8"     "60" "3" 0 0
    "000001" 2016 "4,5,6,7,8" "54" "4" 0 0
    "000001" 2016 "5,6,7"     "53" "5" 0 0
    "000001" 2017 "5,6,7"     "53" "4" 0 0
    "000001" 2017 "5,7,8"     "61" "3" 0 0
    "000001" 2017 "5,7,8"     "49" "4" 0 1
    "000001" 2017 "5,7,8"     "46" "4" 0 0
    "000001" 2017 "7,9"       "62" "4" 0 1
    "000001" 2017 "4,5,6,7,8" "55" "4" 1 0
    end

    Hope you help me in this, and thanks in advance.

  • #2
    Code:
    //  VERIFY THERE IS AT MOST ONE CEO AT ANY TIME
    by Stkcd Year, sort: egen checksum = total(isCEO)
    assert checksum <= 1
    
    //  ASSIGN DIRECTOR ID
    by Stkcd Year, sort: gen int director = _n
    
    //  REORGANIZE THE FUNBACK VARIABLE AND MAKE AGE, DEGREE, NUMERIC
    destring Age Degree, replace
    split Funback, parse(",") gen(background) destring
    
    //  GO LONG
    reshape long background, i(Stkcd Year director)
    drop if missing(background)
    
    //  CALCULATE V1
    by Stkcd Year background (isCEO), sort: gen byte V1 = (isCEO[1] != isCEO[_N])
    by Stkcd Year director (V1), sort: replace V1 = V1[_N]
    
    //  CALCULATE V2
    reshape wide
    drop background*
    by Stkcd Year  (isCEO), sort: gen byte V2 = (Degree == Degree[_N])
    
    //  CALCULATE V3
    by Stkcd Year (isCEO), sort: gen byte V3 = abs(Age - Age[_N]) <= 10
    
    isid Stkcd Year director, sort
    Note: The questions posed are only meaningful if, in each year, each firm as at most 1 director designated as CEO. This is true in the example data shown. The code verifies this assumption. If the -assert- command gives an error message, this assumption is not met--and in that case the data cannot be used to answer these questions. It is also likely, in that case, that the data are incorrect and need to be fixed.
    Last edited by Clyde Schechter; 02 Mar 2023, 18:30. Reason: Correct error in original code.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Code:
      // VERIFY THERE IS AT MOST ONE CEO AT ANY TIME
      by Stkcd Year, sort: egen checksum = total(isCEO)
      assert checksum <= 1
      
      // ASSIGN DIRECTOR ID
      by Stkcd Year, sort: gen int director = _n
      
      // REORGANIZE THE FUNBACK VARIABLE AND MAKE AGE, DEGREE, NUMERIC
      destring Age Degree, replace
      split Funback, parse(",") gen(background) destring
      
      // GO LONG
      reshape long background, i(Stkcd Year director)
      drop if missing(background)
      
      // CALCULATE V1
      by Stkcd Year background (isCEO), sort: gen byte V1 = (isCEO[1] != isCEO[_N])
      by Stkcd Year director (V1), sort: replace V1 = V1[_N]
      
      // CALCULATE V2
      reshape wide
      drop background*
      by Stkcd Year (isCEO), sort: gen byte V2 = (Degree == Degree[_N])
      
      // CALCULATE V3
      by Stkcd Year (isCEO), sort: gen byte V3 = abs(Age - Age[_N]) <= 10
      
      isid Stkcd Year director, sort
      Note: The questions posed are only meaningful if, in each year, each firm as at most 1 director designated as CEO. This is true in the example data shown. The code verifies this assumption. If the -assert- command gives an error message, this assumption is not met--and in that case the data cannot be used to answer these questions. It is also likely, in that case, that the data are incorrect and need to be fixed.
      Thank you so much It works.

      Comment

      Working...
      X