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: RE: RE: RE: RE: RE: RE: correlation, panel data


From   "Biljana Dlab" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: RE: RE: RE: correlation, panel data
Date   Thu, 14 Oct 2010 15:39:57 +0200

It is fine - we can skip this...

I calculated it step by step and got what I wanted.

Thanks a lot for the help.

Will talk to IT guys and get that useful function install.

Best,

Biba

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Biljana Dlab
Sent: 14 October 2010 15:02
To: [email protected]
Subject: st: RE: RE: RE: RE: RE: correlation, panel data

With this code just vector of dots is generated.

When the loop started, I did not get 2., ...


. 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 {
. capture corr cf r_d if gvkey_n==`l'
. if _rc == 0 {
. replace corr=r(rho) if gvkey_n==`l'
. }
. }

. browse

Thanks a lot.

Best,
Biljana

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

tsset  gvkey_n  fyear
levelsof gvkey_n, local(levels)
gen corr=.
qui foreach l of local levels {
	capture corr cf r_d if gvkey_n==`l'
	if _rc == 0 { 
		replace corr=r(rho) if gvkey_n==`l'
	} 
}

Nick 
[email protected] 

Nick Cox

Put -capture corr- rather than -corr-. 

This rather underlines that if some of your panels are very short, then those correlations will be based on very few values, with consequent problems. For example, a correlation based on two distinct y and two distinct x points will necessarily be 1 or -1. A correlation based on no or one point cannot be calculated. 

Biljana Dlab

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
r(2000);

Nick Cox

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'
}


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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