Announcement

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

  • How do I calculate average pairwise correlation?

    Dear all,
    Hi, I have a dataset, where P_(i,j,t) is the stock price of firm i in sector j at time t.
    I am interested in,
    1. calculating average pairwise correlation of stock prices between firms in the same sector;
    2. calculating average pairwise correlation of stock prices between firms in two different sectors.
    I feel like there must be an efficient way of doing this, but I'm not aware of it. I'd really appreciate your guidance. Thank you!

    Best,
    John

  • #2
    Why doesn't using "corr" work? A fast way of doing it is to use loops and making good use of locals. For example, here's one:

    corr res_leis_hour dlgdp
    local temp1: di %3.2f r(rho)

    that saves the corr between the two variables to the temp1 local that you can call later and insert into a matrix, for example

    Comment


    • #3
      You may want to look at the mixed effects estimators if you need to decompose things into within and between industry effects/correlations. The icc command may also be useful for you.

      Comment


      • #4
        this is an odd use of the command, but alpha varlist, det std will give the average interitem correlation for a list of variables. Is that what you're after?

        Comment

        Working...
        X