Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Average correlations in panel data


From   yoel ben or <[email protected]>
To   [email protected]
Subject   st: Average correlations in panel data
Date   Mon, 10 Feb 2014 21:18:03 +0200

I have a dataset that looks like this:

compid ret     month    year     retdate     mktval      decile
10006   -.05588235   1983       8     1983m8   262731.3          7
10006    .57480317   1983       9     1983m9     415950          7
10006        -.025   1983      10    1983m10   405551.3          7
10006    .05333333   1983      11    1983m11     426462          7
10006   -.01960784   1983      12    1983m12     419250          7
10001   -.07407408   1987       2     1987m2    6193.75          1
10001        .0368   1987       3     1987m3   6317.625          1
10001    .05142857   1987       6     1987m6   5822.125          1
10001     .0212766   1987       7     1987m7       5946          1
10001    .08333334   1987       8     1987m8     6441.5          1
10487    .10226244   1983       8     1983m8   327819.3          7
10487    .02479339   1983       9     1983m9     335947          7
10487    .08870967   1983      10    1983m10   365748.8          7
10487    .02074074   1983      11    1983m11   371167.3          7
:
:
:

where compid and retdate uniquely identify ret(urn) observations for
a company's stock market returns in a particular month. Decile
corresponds to the decile of market value for the company, and years
run from 1930-2006. What I'm trying to obtain is the average of all
pairwise correlations for company returns over subperiods defined by
dates (i.e. 1970-1975) and by subgroups defined by decile. One
solution would seem to be to run through the data with forval,
dropping all observations that don't correspond to the subgroup/
subperiod intersection, then reshape to wide (or alternatively xpose)
to give me variables that look like for instance:

retdate ret10006 ret10487
1983m8 -.05588235 .10226244
1983m9 .57480317 .02479339
:
:

and then hand the variables ret10006 and ret10487 to a corr function,
but  it seems very
inefficient.

Is there a better way method than the brute force drop/reshape?
There must be...I just don't really know how.  Plus the brute force
approach doesn't really make it easy to store the actual average
correlation series.

Thanks for any of your help,
Joel
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index