Dear Statalisters,
My panel data is organized by industry , firm, year, quarter. I present the first 40 observations below. I want to compute the correlation coefficient on a rolling 5-year(20 quarter) basis for each firm, then take the mean within each industry year. I only used pwcorr before, but never on a rolling basis.
Could you help?
gvkey: firm identifier
sic: industry classification
fyear: fiscal year
qtr: quarter 1,2,3,4
correlation to be computed between x1 and x2
clear
input int gvkey byte sic int fyear byte qtr double(x1 x2)
1000 30 2008 1 16.52 112.59
1000 30 2008 2 16.16 110.87
1000 30 2008 3 15.9 102.54
1000 30 2008 4 16.200001 103.84
1000 30 2009 1 16.139999 104.49
1000 30 2009 2 16.120001 104.82
1000 30 2009 3 16.190001 103.66
1000 30 2009 4 15.64 102.82
1000 30 2010 1 15.52 103.38
1000 30 2010 2 15.52 103.24
1000 30 2010 3 15.58 102.76
1000 30 2010 4 15.75 102.95
1000 30 2011 1 15.75 101.77
1000 30 2011 2 15.69 101.9
1000 30 2011 3 15.69 101.17
1000 30 2011 4 15.38 99.790001
1000 30 2012 1 15.55 98.779999
1000 30 2012 2 15.58 98.529999
1000 30 2012 3 15.35 97.480003
1000 30 2012 4 15.52 95.959999
1001 30 2008 1 185.5 111.1
1001 30 2008 2 183.56 108.38
1001 30 2008 3 179.7 102.08
1001 30 2008 4 185.51 103.42
1001 30 2009 1 185.74001 104.15
1001 30 2009 2 185.17999 103.41
1001 30 2009 3 184.96001 101.6
1001 30 2009 4 179.51 102.43
1001 30 2010 1 180.97 102.63
1001 30 2010 2 180.23 102.51
1001 30 2010 3 179.19 102.27
1001 30 2010 4 181.07001 101.77
1001 30 2011 1 182.23 100.34
1001 30 2011 2 180.32001 101.16
1001 30 2011 3 180.7 100.2
1001 30 2011 4 177.01 97.129997
1001 30 2012 1 176.02 97.669998
1001 30 2012 2 173.76 97.760002
1001 30 2012 3 171.86 96.809998
1001 30 2012 4 173.02 95.779999
. . . . . .
end
[/CODE]
Regards,
Rochelle
My panel data is organized by industry , firm, year, quarter. I present the first 40 observations below. I want to compute the correlation coefficient on a rolling 5-year(20 quarter) basis for each firm, then take the mean within each industry year. I only used pwcorr before, but never on a rolling basis.
Could you help?
gvkey: firm identifier
sic: industry classification
fyear: fiscal year
qtr: quarter 1,2,3,4
correlation to be computed between x1 and x2
clear
input int gvkey byte sic int fyear byte qtr double(x1 x2)
1000 30 2008 1 16.52 112.59
1000 30 2008 2 16.16 110.87
1000 30 2008 3 15.9 102.54
1000 30 2008 4 16.200001 103.84
1000 30 2009 1 16.139999 104.49
1000 30 2009 2 16.120001 104.82
1000 30 2009 3 16.190001 103.66
1000 30 2009 4 15.64 102.82
1000 30 2010 1 15.52 103.38
1000 30 2010 2 15.52 103.24
1000 30 2010 3 15.58 102.76
1000 30 2010 4 15.75 102.95
1000 30 2011 1 15.75 101.77
1000 30 2011 2 15.69 101.9
1000 30 2011 3 15.69 101.17
1000 30 2011 4 15.38 99.790001
1000 30 2012 1 15.55 98.779999
1000 30 2012 2 15.58 98.529999
1000 30 2012 3 15.35 97.480003
1000 30 2012 4 15.52 95.959999
1001 30 2008 1 185.5 111.1
1001 30 2008 2 183.56 108.38
1001 30 2008 3 179.7 102.08
1001 30 2008 4 185.51 103.42
1001 30 2009 1 185.74001 104.15
1001 30 2009 2 185.17999 103.41
1001 30 2009 3 184.96001 101.6
1001 30 2009 4 179.51 102.43
1001 30 2010 1 180.97 102.63
1001 30 2010 2 180.23 102.51
1001 30 2010 3 179.19 102.27
1001 30 2010 4 181.07001 101.77
1001 30 2011 1 182.23 100.34
1001 30 2011 2 180.32001 101.16
1001 30 2011 3 180.7 100.2
1001 30 2011 4 177.01 97.129997
1001 30 2012 1 176.02 97.669998
1001 30 2012 2 173.76 97.760002
1001 30 2012 3 171.86 96.809998
1001 30 2012 4 173.02 95.779999
. . . . . .
end
[/CODE]
Regards,
Rochelle
Comment