Hi Everyone,

I have currency data that I want to initially sort on NFA(Net Foreign Assets) into two groups. Then I want to further divide the groups into 5 portfolios based on WLDC1 ( share of local liabilities) and NFA. Further elaboration, countries with low NFA (based on the initial sort) will be in group 1, 2 and 3 and amongst this group countries with lowest WLDC1 will be in group one. Similarly, Countries with the highest NFA, will be in group 3,4 and 5 and those with the highest WLDC1 will be in group 5.

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str18 country float(country_id time_id fretinv) double(NFAGDP wldc1)
"belgium"      2  1   -.021109786 -.0880785331526785  .14162569999999874
"norway"      12  1   -.013094058 -.2739256831068258  .04839210000000094
"canada"       3  1   -.005505595 -.3678204204571775  .39095930000000223
"sweden"      13  1   -.023506006 -.1975385911769849 -.12746400000000335
"danish"       4  1   -.022279274 -.3920655988367886 -.09925630000000751
"germany"      7  1    -.03913917  .0639284917157848   .7776842999999971
"italy"        8  1    -.01357121 -.0446405665547884   .2852137999999993
"netherlands" 10  1   -.031622995  .1907897667834038  .29473870000000346
"japan"        9  1   -.021172235  .0298053656560809   .3924848999999999
"norway"      12  2     -.0029399 -.2739256831068258  .04839210000000094
"danish"       4  2 -.00004334668 -.3920655988367886 -.09925630000000751
"canada"       3  2    .005517004 -.3678204204571775  .39095930000000223
"belgium"      2  2   .0021488247 -.0880785331526785  .14162569999999874
"sweden"      13  2  -.0014094796 -.1975385911769849 -.12746400000000335
"japan"        9  2   -.002983813  .0298053656560809   .3924848999999999
"germany"      7  2    .005002804  .0639284917157848   .7776842999999971
"italy"        8  2    .007087627 -.0446405665547884   .2852137999999993
"netherlands" 10  2   -.004208108  .1907897667834038  .29473870000000346
"sweden"      13  3  -.0002060555 -.1975385911769849 -.12746400000000335
"danish"       4  3     .01471494 -.3920655988367886 -.09925630000000751
"belgium"      2  3   .0008446722 -.0880785331526785  .14162569999999874
"canada"       3  3   -.005583578 -.3678204204571775  .39095930000000223
"norway"      12  3  .00006450686 -.2739256831068258  .04839210000000094
"germany"      7  3  -.0002343281  .0639284917157848   .7776842999999971
"netherlands" 10  3   -.019338237  .1907897667834038  .29473870000000346
"japan"        9  3   -.004173314  .0298053656560809   .3924848999999999
"italy"        8  3    -.01559818 -.0446405665547884   .2852137999999993
"belgium"      2  4   -.016093174 -.0880785331526785  .14162569999999874
"sweden"      13  4  -.0013311518 -.1975385911769849 -.12746400000000335
"danish"       4  4   -.016139347 -.3920655988367886 -.09925630000000751
"norway"      12  4     .01577214 -.2739256831068258  .04839210000000094
"canada"       3  4   .0046203765 -.3678204204571775  .39095930000000223
"germany"      7  4    -.02136351  .0639284917157848   .7776842999999971
"japan"        9  4   .0009061149  .0298053656560809   .3924848999999999
"italy"        8  4    -.00922169 -.0446405665547884   .2852137999999993
"netherlands" 10  4    -.02105068  .1907897667834038  .29473870000000346
"canada"       3  5   -.004730247 -.3678204204571775  .39095930000000223
"belgium"      2  5   -.037031196 -.0880785331526785  .14162569999999874
"sweden"      13  5    -.00871673 -.1975385911769849 -.12746400000000335
"norway"      12  5   -.008771247 -.2739256831068258  .04839210000000094
"danish"       4  5     -.0395399 -.3920655988367886 -.09925630000000751
"germany"      7  5    -.03749972  .0639284917157848   .7776842999999971
"japan"        9  5    -.01259469  .0298053656560809   .3924848999999999
"netherlands" 10  5   -.034326673  .1907897667834038  .29473870000000346
"italy"        8  5    -.02509037 -.0446405665547884   .2852137999999993
"danish"       4  6   -.002543347 -.3920655988367886 -.09925630000000751
"sweden"      13  6   -.006772406 -.1975385911769849 -.12746400000000335
"canada"       3  6    .004304801 -.3678204204571775  .39095930000000223
"belgium"      2  6   .0013257583 -.0880785331526785  .14162569999999874
"norway"      12  6   -.010822061 -.2739256831068258  .04839210000000094
"netherlands" 10  6   .0032686586  .1907897667834038  .29473870000000346
"germany"      7  6   -.000711034  .0639284917157848   .7776842999999971
"italy"        8  6    .007813968 -.0446405665547884   .2852137999999993
"japan"        9  6    .001056091  .0298053656560809   .3924848999999999
"sweden"      13  7   -.024422616 -.1975385911769849 -.12746400000000335
"norway"      12  7   -.015327682 -.2739256831068258  .04839210000000094
"belgium"      2  7     -.0545189 -.0880785331526785  .14162569999999874
"canada"       3  7   -.006287212 -.3678204204571775  .39095930000000223
"danish"       4  7    -.05190312 -.3920655988367886 -.09925630000000751
"germany"      7  7    -.05663233  .0639284917157848   .7776842999999971
"japan"        9  7    -.02311087  .0298053656560809   .3924848999999999
"netherlands" 10  7    -.05419422  .1907897667834038  .29473870000000346
"italy"        8  7    -.04686244 -.0446405665547884   .2852137999999993
"canada"       3  8    .000800399 -.3678204204571775  .39095930000000223
"danish"       4  8   -.010378644 -.3920655988367886 -.09925630000000751
"norway"      12  8   .0022712252 -.2739256831068258  .04839210000000094
"belgium"      2  8   -.010646736 -.0880785331526785  .14162569999999874
"sweden"      13  8   -.013207018 -.1975385911769849 -.12746400000000335
"netherlands" 10  8   -.010457384  .1907897667834038  .29473870000000346
"italy"        8  8   -.008723919 -.0446405665547884   .2852137999999993
"germany"      7  8    -.00836197  .0639284917157848   .7776842999999971
"japan"        9  8   -.014393727  .0298053656560809   .3924848999999999
"sweden"      13  9    .013920554 -.1975385911769849 -.12746400000000335
"norway"      12  9    .025404394 -.2739256831068258  .04839210000000094
"belgium"      2  9    .018464683 -.0880785331526785  .14162569999999874
"danish"       4  9     .02724279 -.3920655988367886 -.09925630000000751
"canada"       3  9    .001372495 -.3678204204571775  .39095930000000223
"germany"      7  9      .0237997  .0639284917157848   .7776842999999971
"netherlands" 10  9     .02563135  .1907897667834038  .29473870000000346
"italy"        8  9    .020227265 -.0446405665547884   .2852137999999993
"japan"        9  9     .05330905  .0298053656560809   .3924848999999999
"danish"       4 10   -.009854814 -.3920655988367886 -.09925630000000751
"norway"      12 10   -.007568355 -.2739256831068258  .04839210000000094
"sweden"      13 10   -.006037047 -.1975385911769849 -.12746400000000335
"belgium"      2 10   -.011842554 -.0880785331526785  .14162569999999874
"canada"       3 10  -.0015955273 -.3678204204571775  .39095930000000223
"germany"      7 10   -.016129803  .0639284917157848   .7776842999999971
"japan"        9 10   -.007225025  .0298053656560809   .3924848999999999
"netherlands" 10 10    -.01790737  .1907897667834038  .29473870000000346
"italy"        8 10   -.005620233 -.0446405665547884   .2852137999999993
"danish"       4 11   -.019913414 -.3920655988367886 -.09925630000000751
"canada"       3 11   -.005236065 -.3678204204571775  .39095930000000223
"norway"      12 11   -.007730458 -.2739256831068258  .04839210000000094
"belgium"      2 11   -.017782051 -.0880785331526785  .14162569999999874
"sweden"      13 11   -.013169602 -.1975385911769849 -.12746400000000335
"germany"      7 11   -.021317545  .0639284917157848   .7776842999999971
"netherlands" 10 11   -.019564146  .1907897667834038  .29473870000000346
"japan"        9 11    .006952212  .0298053656560809   .3924848999999999
"italy"        8 11   -.011620821 -.0446405665547884   .2852137999999993
"norway"      12 12   -.023439156 -.2739256831068258  .04839210000000094
end