Announcement

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

  • Calculate auditor tenure from Compustat data

    Dear all,

    I am trying to calculate auditor tenure by counting the amount of years an auditor works for a specific company. This variable should be increasing by the increasing number of years the auditor works for the client. I have the following at this moment (retrieved from dataex):

    input str6 gvkey double fyear str8 au
    "001001" 1983 "6"
    "001001" 1984 "6"
    "001001" 1985 "6"
    "001003" 1988 "5"
    "001003" 1989 "5"
    "001003" 1982 "8"
    "001003" 1983 "8"
    "001003" 1984 "8"
    "001003" 1985 "8"
    "001003" 1986 "8"
    "001003" 1987 "8"
    "001004" 1979 "1"
    "001004" 1980 "1"
    "001004" 1981 "1"
    "001004" 1982 "1"
    "001004" 1983 "1"
    "001004" 1984 "6"
    "001004" 1985 "6"
    "001004" 1986 "6"
    "001004" 1987 "6"
    "001004" 1988 "6"
    end
    [/CODE]


    I want to create a variable au_tenure which should look like the following:

    gvkey fyear au au_tenure
    "001001" 1983 "6" 1
    "001001" 1984 "6" 2
    "001001" 1985 "6" 3
    "001003" 1982 "8" 1
    "001003" 1983 "8" 2
    "001003" 1984 "8" 3
    "001003" 1985 "8" 4
    "001003" 1986 "8" 5
    "001003" 1987 "8" 6
    "001003" 1988 "5" 1
    "001003" 1989 "5" 2
    "001004" 1979 "1" 1
    "001004" 1980 "1" 2
    "001004" 1981 "1" 3
    "001004" 1982 "1" 4
    "001004" 1983 "1" 5
    "001004" 1984 "6" 1
    "001004" 1985 "6" 2
    "001004" 1986 "6" 3
    "001004" 1987 "6" 4
    "001004" 1988 "6" 5


    I saw another another question at this forum about the same topic (https://www.statalist.org/forums/for...e-in-compustat). However, when I use the given answer to this question, the order of my fyear changes and if that happens my variable tenure will no longer be correct. The code I used was:

    bysort gvkey au (fyear) : gen AU_TENURE = sum(fyear > 1978)

    And this is what happens to some of the data:

    input str6 gvkey double fyear str8 au float AU_TENURE
    "001075" 1982 "5" 1
    "001075" 1983 "5" 2
    "001075" 1984 "5" 3
    "001075" 1985 "5" 4
    "001075" 1986 "5" 5
    "001075" 1987 "5" 6
    "001075" 1988 "5" 7
    "001075" 1989 "5" 8
    "001075" 1990 "5" 9
    "001075" 1991 "5" 10
    "001075" 1994 "5" 11
    "001075" 1995 "5" 12
    "001075" 1996 "5" 13
    "001075" 1997 "5" 14
    "001075" 1998 "5" 15
    "001075" 1999 "5" 16
    "001075" 2000 "5" 17
    "001075" 1992 "9" 1
    "001075" 1993 "9" 2
    end
    [/CODE]

    And what I actually want is the following:

    gvkey fyear au AU_TENURE
    "001075" 1982 "5" 1
    "001075" 1983 "5" 2
    "001075" 1984 "5" 3
    "001075" 1985 "5" 4
    "001075" 1986 "5" 5
    "001075" 1987 "5" 6
    "001075" 1988 "5" 7
    "001075" 1989 "5" 8
    "001075" 1990 "5" 9
    "001075" 1991 "5" 10
    "001075" 1994 "5" 1
    "001075" 1995 "5" 2
    "001075" 1996 "5" 3
    "001075" 1997 "5" 4
    "001075" 1998 "5" 5
    "001075" 1999 "5" 6
    "001075" 2000 "5" 7
    "001075" 1992 "9" 1
    "001075" 1993 "9" 2
    end
    [/CODE]


    Could someone maybe help me with this?

    Thanks a lot in advance!

    Celeste

Working...
X