Bookmark and Share

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

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

st: RE: RE: correlation, panel data

From   "Biljana Dlab" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: correlation, panel data
Date   Wed, 13 Oct 2010 21:33:28 +0200

I tried to adjust the code, and am getting good results for the first two companies, but then it stops.

This is how I did it:

. tsset  gvkey_n  fyear
       panel variable:  gvkey_n (unbalanced)
        time variable:  fyear, 1971 to 2001, but with gaps
                delta:  1 unit

. levelsof gvkey_n, local(levels)

. gen corr=.
(7609 missing values generated)

. qui foreach l of local levels {
. corr cf r_d if gvkey_n==`l'
. replace corr=r(rho) if gvkey_n==`l'
. }
no observations


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 13 October 2010 18:49
To: '[email protected]'
Subject: st: RE: correlation, panel data

One possibility without installing anything is to modify this recipe:

sysuse auto
levelsof rep78, local(levels)
gen corr = .
qui foreach l of local levels {
	corr mpg weight if rep78 == `l'
	replace corr = r(rho) if rep78 == `l'

[email protected] 

Biljana Dlab

I have panel data (sorted by gvkey_n and financial years).

Now I am trying to compute correlation between variables r_d and cf - I would like to have this correlation in a separate column in spread-sheet and that the correlation coefficient is written for all firm-year observations

With other words this is what I would like to get:

gvkey_n 	year corr(between r_d&cf)
555		99	0.2
555		00	0.2
555		01	0.2
555		02	0.2
333		99	0.4
333		00	0.4
333		01	0.4

I tried like this:
.by gvkey_n: corr cf r_d  - but then I get matrix (for all companies, very long list in my black stata field)

-> gvkey_n = 63651

             |      r_d 	cf
         r_d |   1.0000
   	   cf	 |   0.0620   1.0000

How do I select the r_d & cf combination form the matrix put it in separate column in my spreadsheet for each firm?

If I try:
. by gvkey_n: egen d_corr = corr(cf r_d) unrecognized command:  _gcorr r(199);

. ssc install egenmore
checking egenmore consistency and verifying not already installed...
file C:\DOCUME~1\dlab\LOCALS~1\Temp\ST_0100000g.tmp already exists could not copy
(no action taken)

Do you know the function how to get correlation in the column?

*   For searches and help try:

*   For searches and help try:

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