Announcement

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

  • How to calculate overlap rate for a firm's peer group from year to year

    I would like to calculate a overlap rate (or you can treat it as a change rate) for focal firms' peer group from year to year. the data is something like this:

    focal_firm peer_firm year
    001 021 2000
    001 022 2000
    001 021 2001
    001 022 2001
    001 023 2001
    001 021 2002
    001 023 2002
    001 024 2002
    002 021 2000
    002 024 2000
    002 022 2001
    002 024 2001
    002 022 2002
    002 024 2002
    ......

    I would like to check how peer group change compared with previous year. For example, for focal firm 001, its peer group similarity is 2/3 (2 same peer firms / 3 peer firms in total on 2001) from year 2001 to year 2002.
    one of the biggest problem is I do not know how to set time series variable (focal_firm year) when there is duplicates.

    Thank you very much for your help!

    Best,
    Yongda

  • #2
    There is no need to -tsset- the data for this.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3(focal_firm peer_firm) int year
    "001" "021" 2000
    "001" "022" 2000
    "001" "021" 2001
    "001" "022" 2001
    "001" "023" 2001
    "001" "021" 2002
    "001" "023" 2002
    "001" "024" 2002
    "002" "021" 2000
    "002" "024" 2000
    "002" "022" 2001
    "002" "024" 2001
    "002" "022" 2002
    "002" "024" 2002
    end
    
    by focal_firm peer_firm (year), sort: gen byte unchanged = (year[_n+1] == year + 1)
    by focal_firm year (peer_firm), sort: egen proportion_retained = mean(unchanged)
    In the future, when showing data examples, please use the -dataex- command to do so, as I have here. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thank you very much for your help, Clyde! I will use the -dataex- command next time.

      Comment

      Working...
      X