Announcement

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

  • Create Firmage variable

    Hey guys,

    this is the first time that I am using Stata. I do have a panel data set, which includes various balance sheet data for different firms over several years each.
    Now I want to create a variable that gives the firm-age for every single fiscal year and every single company. Firm-age therefor is defined as current fiscal year minus first fiscal year, that is observed for that particular firm. For better understanding I tried to upload a excel file, in which I computed the age variable manually. In this example S&P Identifier identifies the firms, hence the example includes two firms (1000 and 1001).

    Unfortunately I do not have any idea how to do this in Stata. What commands do I need for that?

    Can anyone help me please.

    Thanks a lot.

    Regards,
    Diedrich Friedrich

  • #2
    Your link just takes us to our German cousin. In any case, please don't post Excel files here. This is explained in the FAQ Advice.

    Code:
     
    bysort firmid (year) : gen age = year - year[1]
    may be enough. See also http://www.stata-journal.com/sjpdf.h...iclenum=dm0055 for a review of technique.

    Comment


    • #3
      So assuming you have a variable called firm_id and another called year, which denotes the year of the current observation:

      Code:
      by firm_id (year), sort: gen firm_age = year - year[1]
      Reading up in the user manuals on the use of -by- and the meaning of 1, _n, and _N in connection with -by- will unlock the door to many important data management processes.

      Comment


      • #4
        Diedrich: This should do it. Stata is very user-friendly, so in time, you will quickly pick up!

        Code:
        sort  S_P_Identifier fiscal_year
        by  S_P_Identifier: gen difference =  fiscal_year - fiscal_year[_n-1]
        replace difference=0 if  difference==.
        by  S_P_Identifier: gen age=  sum(difference)

        Comment

        Working...
        X