I have a data.frame that needs double-sorting, part of it is as below
PERMNO mktcap coef
13974 11711 37.5000 1.2508261
24798 13071 72.8750 0.7413084
15294 11869 75.0000 0.3820783
33114 14170 111.3750 2.3607454
24270 13004 131.2500 4.0205943
37866 14699 131.2500 1.8548012
32190 13995 135.0000 1.7028044
30078 13768 149.2500 1.3376186
28494 13530 150.0000 1.7675992
27966 13469 188.1250 1.3499105
16350 12001 210.3750 1.7627097
30870 13848 225.0000 1.7692176
29154 13581 272.2500 1.6714913
33906 14277 309.3750 2.0797843
39186 14816 322.8750 1.6204331
7638 10911 332.7500 1.0864174
9882 11201 339.0000 1.8405390
38922 14787 363.1250 0.9696966
40638 15018 376.8750 1.5077336
34302 14306 411.7500 1.4610924
8298 11017 453.1250 2.0834445
40770 15034 528.9375 2.3746428
33774 14269 531.3750 2.0195085
32322 14007 560.6250 1.7508435
45258 15560 572.0625 2.2281513
10806 11332 577.5000 1.3420006
30342 13784 593.1250 2.0868992
22026 12722 596.7500 1.2661233
12918 11535 640.0000 2.3642444
43014 15253 641.2500 0.8406199
I need to divide all observations into 100 groups. The procedure involves two steps: first, divide all observations into 10 groups with equal observations in terms of the value of the variable mktcap; second, for each group, further divided the observations within a group into 10 groups with equal observations in terms of the value of the variable coef. Then add a new variable indicating the group of each observation. The value of this new variable should range from p1 to p100.