Announcement

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

  • Panel data

    I have a data set which includes firm id's and a year variable, e.g.

    id Year

    1 2004
    1 2005
    1 2006
    2 2006
    2 2007
    3 2005

    etc


    Is there a way I can calculate the numbers of new id's (firms) each year, and the number of id's that leave each year?

    Thank you for your help

  • #2
    Quick but rough solution: set panel: tsset id Year, and simply create two dummy variables as follows: bysort year: gen missinglag = (l1.id == .); bysort year: gen missingforward = (f1.id == .) ; count them by year: bysort year: egen count... = total(missing...)

    Comment


    • #3
      Harald: Missing L1. identifiers occur at the beginning of each panel, but also if there are any gaps within panels.

      I would do something like this:

      Code:
      bysort id (year) : gen flag = cond(_n == 1, 1, cond(_n == _N, -1, 0))
      or equivalently

      Code:
      bysort id (year) : gen flag = (_n == 1) - (_n == _N)
      Then the numbers concerned are

      Code:
      egen entry = total(flag == 1), by(year)
      egen exit = total(flag == -1), by(year)
      You may want to select just one value for display

      Code:
       
      egen tag = tag(year) 
      sort year 
      l year entry exit if tag
      Last edited by Nick Cox; 16 Feb 2015, 10:48.

      Comment

      Working...
      X