Dear Statalisters,
I have a problem and desperately need your help. My data is organised as below: a variable Date, other variables (x1, x2, x3) that contain returns of stocks 1, 2 and 3 for the specific month.
I need to compute the 24-months correlation between each stock (x1 & x2 as well as x1 & x3 as well as x2 & x3) every quarter IF the last 24 months contains at least 12 returns (as you can see below, x3 doesn't have any data after June 1995). Precisely I need: Correlation between x1 and x2 from 1/31/94 to 12/31/95 if both variables have at least 12 data points in those months.
I also need the correlation between those two variables for the period 4/30/94 to 3/31/96 etc....
I need to do that between all my variables, which means that I will end up with a correlation matrix every 3-month. I need to cluster these correlations in order to see if the "buckets" will change through time...
I have spent 3 days on this, and I can't seem to find the right solution!
I need your help!!
Thanks a lot,
Q.
I have a problem and desperately need your help. My data is organised as below: a variable Date, other variables (x1, x2, x3) that contain returns of stocks 1, 2 and 3 for the specific month.
I need to compute the 24-months correlation between each stock (x1 & x2 as well as x1 & x3 as well as x2 & x3) every quarter IF the last 24 months contains at least 12 returns (as you can see below, x3 doesn't have any data after June 1995). Precisely I need: Correlation between x1 and x2 from 1/31/94 to 12/31/95 if both variables have at least 12 data points in those months.
I also need the correlation between those two variables for the period 4/30/94 to 3/31/96 etc....
I need to do that between all my variables, which means that I will end up with a correlation matrix every 3-month. I need to cluster these correlations in order to see if the "buckets" will change through time...
I have spent 3 days on this, and I can't seem to find the right solution!
I need your help!!
Thanks a lot,
Q.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int Date double(x1 x2 x3) 1/31/94 -.0041000000000000 .00390000000000055 .0140056022408962 2/28/94 -.0140572703607288 -.0347000000000049 .0359116022099448 3/31/94 -.013578756789378501 -.0462000000000001 -.024 4/30/94 -.0127714897522177 -.00229999999999944 -.075591985428051 5/31/94 .00650708807808508 .0604000000000079 -.084729064039409 6/30/94 -.0188563072423613 .0362999999999932 .023681377825619 7/31/94 .01757138374647 -.021399999999997598 .028391167192429 8/31/94 .0262102991057663 .00819999999999676 -.0214723926380367 9/30/94 .0204326923076923 .00540000000000324 -.039707419017763895 10/31/94 -.011925795053003601 -.019900000000000598 .026115342763873797 11/03/94 -.032856504246759004 .032700000000001304 .0381760339342523 12/31/94 -.0368230490717202 .0217 -.069458631256384 1/31/95 -.0007998080460688981 -.0654000000000033 -.0779363336992315 2/28/95 -.027455375010005702 -.0036999999999978 .0345238095238094 3/31/95 .0554732510288067 .0463000000000038 -.054085155350978 4/30/95 .0168434185901435 -.00200000000000461 .0231143552311435 5/31/95 .0197852760736195 .015299999999999201 .124851367419738 6/30/95 .0117310873815612 -.049799999999999095 . 7/31/95 .004979931618849531 .060699999999999 . 8/31/95 .030914873160269002 .145400000000003 . 9/30/95 .0149221608436761 -.0025000000000030696 . 10/31/95 .0351311232063335 .0222000000000074 . 11/30/95 -.0127014476918874 .11299999999999899 . 12/31/95 -.006363259095310661 .07459999999999939 . 1/31/96 .0603508283447029 .0552000000000001 . 2/28/96 .010175277358366598 -.0904000000000026 . 3/31/96 -.008253184299454 .0679999999999978 . 4/30/96 -.000720791560186184 .0318000000000051 . end format %tdnn/dd/CCYY Date
Comment