Announcement

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

  • Is there a better way to calculate firm age?

    Dear Statalisters,

    I'd like to calculate a firm's age based on number of years the firm has been on the database with non-missing stock price data (prcc_c).The threshold is 40, if actual value is higher it gets replaced with 40. The last year for the count is 2019

    I have tried
    Code:
    rangestat (count)datayear, interval(datayear -40 1) by (gvkey)
    , however this does not allow setting the stock-price condition 'if prcc_c<.'. I am also trying to set the interval to 1950-2019 (sampling period)
    for the threshold
    Code:
    replace AGE=40 if AGE>40 & !missing(AGE)
    Can anyone help what would be a more appropriate code?

    Example of data:
    [CODE]
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 gvkey long datadate double fyear str8 tic double prcc_c long ipodate float(ipoyear datayear)
    "001004"  2342 1965 "AIR"           . 10227 1988 1966
    "001004"  2707 1966 "AIR"           . 10227 1988 1967
    "001004"  3073 1967 "AIR"        15.5 10227 1988 1968
    "001004"  3438 1968 "AIR" 22.24998067 10227 1988 1969
    "001004"  3803 1969 "AIR" 12.24998541 10227 1988 1970
    "001004"  4168 1970 "AIR" 17.87498243 10227 1988 1971
    "001004"  4534 1971 "AIR" 22.24995647 10227 1988 1972
    "001004"  4899 1972 "AIR"  24.9999757 10227 1988 1973
    Last edited by Larry Wellings; 03 Jan 2021, 10:51.

  • #2
    If I understand correctly:

    bys gvkey : egen age=total(cond(!mi(prcc_c),inrange(datayear,1950,2 019),0))

    should do it.

    hth,
    Jeph

    Comment


    • #3
      Thank you, this worked

      Comment


      • #4
        Jeph Herrin's solution in #2 is excellent. See Section 9 of https://www.stata-journal.com/articl...article=dm0055 for more discussion of Jeph's technique.

        Otherwise the statement in #1 that

        Code:
        if prcc_c<.
        is not allowed is incorrect. (Larry may well be alluding to code he doesn't show us that failed for some other reason.) A statement starting


        Code:
         rangestat (count) datayear if prcc_c < .
        should work fine. Note, however, that

        Code:
         interval(datayear -40 1)
        defines an interval of length 42 years (think -40 ... -1 0 1) If I understand the problem correctly, Larry wants to check for at least 40 years of observations with non-missing values, in which case


        Code:
        rangestat (count) datayear if prcc_c < ., interval(datayear . . ) by(gvkey)
        counts non-missing values for each firm and ignoring years that are not wanted could be achieved by extending the if condition.
        Last edited by Nick Cox; 04 Jan 2021, 04:32.

        Comment

        Working...
        X