Hi,
I have divided my panel data into 5 portfolios depending on the leverage change. I want to calculate the mean return per portfolio. My data is structured as following:
To calculate the mean return per portfolio, I have used the following code:
And to give me the mean returns per portfolio:
In other post, someone told me to collapse the data, but when I do it, the mean returns differ. To collapse the data I have used:
The resulting data:
My question is, do I have to collapse the data to obtain the mean returns or is the correct way to not collapse the data.
Thanks
I have divided my panel data into 5 portfolios depending on the leverage change. I want to calculate the mean return per portfolio. My data is structured as following:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long gvkey float time double ri float change5 17404 408 6.2868 2 100174 408 .67875385 3 12383 408 20.2034 1 28272 408 -3.0111372 4 15444 408 10.393393 3 100816 408 14.393223 2 101538 408 8.974827 5 100951 408 10.318255 3 100650 408 7.108283 3 102283 408 16.589928 5 104643 408 4.458046 5 18860 408 -.97833276 3 101048 408 22.843945 1 100171 408 25.716532 1 4439 408 11.580002 2 12368 408 16.007114 3 11749 408 9.778547 1 208224 408 10.131335 3 101343 408 4.8086047 4 19565 408 11.478603 2 2411 408 1.5684724 3 14620 408 34.344685 1 63477 408 22.201073 5 100095 408 12.224221 1 102576 408 12.202585 5 102569 408 15.309072 5 16299 408 13.66235 2 100131 408 4.9301624 4 100913 408 4.228711 4 100619 408 20.178556 1 end format %tm time
Code:
bysort change5 year month: egen mean_port = mean(ri)
Code:
forvalues i=1/5 { sum mean_port if (change5 == `i') }
Code:
collapse (mean) ri, by(change5 time year month)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year byte month float(time change5) double mean_port 1995 1 420 1 1.0816451685714283 1995 2 421 1 3.6309387985714285 1995 3 422 1 1.0072868880952377 1995 4 423 1 5.0430555279047615 1995 5 424 1 2.9058011104761903 1995 6 425 1 2.851414689047618 1995 7 426 1 7.513776112857145 1995 8 427 1 -1.9839238423809529 1995 9 428 1 6.297235610476192 1995 10 429 1 -1.9108445761904764 1995 11 430 1 2.716185952380952 1995 12 431 1 2.0948071990476187 1996 1 432 1 2.3413777818181822 1996 2 433 1 2.690949502727273 1996 3 434 1 4.891548433636363 1996 4 435 1 1.2471700777272732 1996 5 436 1 2.880885366818182 1996 6 437 1 2.4656674173913045 1996 7 438 1 -1.8710875078260867 1996 8 439 1 6.912583163478258 1996 9 440 1 .7871459691304344 1996 10 441 1 5.783322285652174 1996 11 442 1 1.7836946360869574 1996 12 443 1 3.0109286543478255 1997 7 450 1 -.43301152388888897 1997 8 451 1 .33338073421052644 1997 9 452 1 8.364553181578946 1997 10 453 1 -.30252995263157895 1997 11 454 1 1.1336856173684209 1997 12 455 1 -1.2938973271052634 end format %tm time
Thanks
Comment