I have 200 stock returns. I want to construct 10 portfolios, using delices sorted by the stock's volatility. Help on how to write a loop for this will highly be appreciated.
Thank you
Thank you
egen portfolios = xtile(volatility), nq(10)
bys year: egen portfolios = xtile(volatility), nq(10)
gen long obs_no = _n reshape long Firm V, i(obs_no) j(_j) xtile decile = V, nq(10)
Date | Firm 1 | Firm 2 | Firm 3 | Firm 4 | Firm 5 | Firm 6 |
4/01/2010 | 0.047164 | -0.09991 | 0.007698 | -0.03226 | -0.03226 | -0.00306 |
5/01/2010 | 0.047063 | -0.1054 | -0.00847 | -0.0435 | -0.0435 | -0.01777 |
6/01/2010 | 0.042946 | 0.024919 | 0.006855 | 0.027033 | 0.027033 | -0.00602 |
7/01/2010 | 0.04271 | -0.05712 | 0.023591 | 0.01817 | 0.01817 | -0.03251 |
8/01/2010 | 0.040565 | -0.04292 | -0.04417 | -0.02588 | -0.02588 | -0.03642 |
9/01/2010 | 0.037597 | -0.00684 | 0.022761 | -0.00361 | -0.00361 | -0.00493 |
10/01/2010 | 0.03731 | 0.041008 | -0.00167 | 0.013533 | 0.013533 | 0.00314 |
11/01/2010 | 0.036982 | 0.037516 | -0.02636 | -0.01258 | -0.01258 | -0.03 |
12/01/2010 | 0.036849 | -0.03332 | -0.01688 | -0.02125 | -0.02125 | -0.01708 |
13/01/2010 | 0.036478 | -0.04201 | 0.000312 | -0.02392 | -0.02392 | -0.01279 |
14/01/2010 | 0.035534 | -0.02668 | 0.000742 | -0.00341 | -0.00341 | 0.007816 |
15/01/2010 | 0.033753 | 0.0432 | -0.00299 | -0.00527 | -0.00527 | 0.005277 |
16/01/2010 | 0.032578 | 0.023811 | 0.031447 | 0.013726 | 0.013726 | 0.009029 |
17/01/2010 | 0.032346 | -0.01103 | -0.00341 | 0.001877 | 0.001877 | -0.02545 |
18/01/2010 | 0.031923 | -0.04964 | 0.008454 | 0.003861 | 0.003861 | -0.00261 |
reshape long Firm1 V1, i(obs_no) j(_j)
reshape long Firm V, i(obs_no) j(_j)
Comment