Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Heatmap of the cluster-ordered distance matrix

    Hello Stata Users,
    I am trying to get the optimal number of clusters for my analysis using dhm package. Unfortunatelly when I run the command:

    dhm, distmat(pwd) idvar(id) by(ward5) order(wards45) levels(100) box

    I get the message:
    hmapmat(): 3499 mm_expand() not found
    <istmt>: - function returned error


    ward5 is my grouping variable
    wards45 is a cluster group variable with a maximal number of clusters (so 45, as much as observations in the subsample)
    Variables used for clustering are beta_cf and beta_dr

    here is the data for the first subsample:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 portfolio byte period double(R_Me TY PE VS EtR_Me N_dr N_cf Rrf return beta_cf beta_dr)
    "FFS1BM1" 1    .024837474 -.29 3.0090558 1.4911677    .0013649322   .037841949   -.014369408 .003766778         .0708  .5904635787010193 1.3764880895614624
    "FFS1BM2" 1    .016748563  .22 2.8351334 1.5758021     .010224121    .02085364   -.014329197 .001799992        -.0042  .5182004570960999 1.6450632810592651
    "FFS1BM3" 1    .015257031  .58 2.5844259 1.5698893     .013699732 -.0072375512   .0087948501 .000931663         .0784  .4328821897506714 1.4169353246688843
    "FFS1BM4" 1   -.018343208  .03 2.9391373 1.5192216     .001023709   .020009396   -.039376312 .002766275        -.0288   .468921035528183 1.3830235004425049
    "FFS1BM5" 1    -.14369247 1.15 1.7649228 2.3771743     .010992791   -.18638088    .031695618 .001149823        -.1094  .5537635087966919 1.3988792896270752
    "FFS2BM1" 1   -.045367954  .55 2.6419338 1.5178514    .0041526487  -.049063272  -.0004573305 .000831078        -.0648 .30447614192962646 1.0523284673690796
    "FFS2BM2" 1    .030592526  .48 2.6800022 1.2189329    .0068181602   .024984967  -.0012106018 .001439981         .0276  .3675742447376251 1.2136952877044678
    "FFS2BM3" 1    .028639635  .57 2.7138053 1.5258512    .0050064418 -.0060030085    .029636202  .00079326         .0223 .39034372568130493 1.1717500686645508
    "FFS2BM4" 1   -.023596366  .98 2.7528053 1.4869551     .014303538  -.025713613   -.012186291 .000819254         .0037 .41375747323036194 1.2099233865737915
    "FFS2BM5" 1   -.030775166  .47 2.6972427 1.4027611    .0090850939  -.029562683   -.010297577 .000924448        -.0533  .4915424585342407 1.3127026557922363
    "FFS3BM1" 1    .025558962  1.7  2.718934 2.4677968    .0092021535   .026130631  -.0097738222   .0000698        -.0234  .3198002874851227  1.169394850730896
    "FFS3BM2" 1    -.01530777 1.79 2.5496474 2.3846822    .0016556196  -.045106995    .028143606   .0000723        -.0192  .2900814712047577  1.028062343597412
    "FFS3BM3" 1  -.0051162938 1.27 2.9739517 2.3271827   -.0016193556  -.018734588    .015237649 .000535963        -.0047  .3246473968029022 1.0994309186935425
    "FFS3BM4" 1    .033973296 1.94 2.6480899 2.5575603   -.0016760375   .035352693  .00029664004  2.920e-06         .0577  .3744144141674042  1.092715859413147
    "FFS3BM5" 1    .042925774  .39 3.1560688 1.6248499    .0015731229   .050231771  -.0088791196 .002116748         .0185  .5144417881965637  1.328500747680664
    "FFS4BM1" 1   -.054466386 1.86 2.5919211 2.4885233     .010479989  -.065118199  .00017182459   .0000102        -.0394 .20152854919433594   .864585280418396
    "FFS4BM2" 1    .027418757  .59 2.6519745 1.3007655     .010090402  -.016197106    .033525461 .001149924         .0351 .27479660511016846 1.0026077032089233
    "FFS4BM3" 1    .048110527   .5 3.0281721 1.5711636    .0041686791   .041080661   .0028611861 .002433441          .059  .3206683099269867 1.0033721923828125
    "FFS4BM4" 1    .010614476  .48 2.8859004 1.3945274    .0086301448  -.022600664    .024584996 .001225909         .0243  .3761606216430664 1.1042019128799438
    "FFS4BM5" 1   .0038267518  .67 2.3434459 2.3892259   -.0013114213   -.01490776    .020045934 .000942304        -.0092  .5378146767616272 1.4193494319915771
    "FFS5BM1" 1    .061486419  .84 2.7686326 1.4738629     .007669178   .042802967    .011014274 .000821829         .0745 .20230945944786072  .8760085701942444
    "FFS5BM2" 1    .017444861   .2 3.0110316  1.594399    .0024549851  -.004157799    .019147675 .002399856         .0011 .19677357375621796  .8236237168312073
    "FFS5BM3" 1    .024616977 1.01 2.3295562 2.1586656     .014826542   .032144893   -.022354458 .000300046         .0224  .2905327379703522  .8989958167076111
    "FFS5BM4" 1    .047855977  .14 3.0129982 1.4107176    .0057573864   .039869001   .0022295897 .001916493          .048  .3474673926830292 1.0803234577178955
    "FFS5BM5" 1    .030652682  .52 2.6253271 1.4385203 -.000078089235   .040619075  -.0098883033  .00096272         .0227 .42107439041137695 1.1999799013137817
    "RISK1"   1  -.0089134341 1.28 2.8690318 2.4369693   -.0093283941   .014253408   -.013838448  .00046798     .01282758 .20771102607250214  .7331721186637878
    "RISK2"   1    .058128412  .32 2.7409704 2.1235241    -.010630567   .079554558   -.010795579 .002291752     .06042789 .25058606266975403  .8762898445129395
    "RISK3"   1   .0059114106  .76 2.8628741 1.4258307     .013305927   -.02023798    .012843463 .001124416    .011783386  .3217814266681671 1.0455232858657837
    "RISK4"   1    .027673325  .34 2.9238103 1.6282092    .0039459074   .034487263   -.010759845 .002266611    .027468289 .38355138897895813 1.2157959938049316
    "RISK5"   1    .033535445 1.53 2.9256647 2.5038816    .0051984068   .010412564    .017924474   .0000734 -.00068372404 .48261430859565735 1.5047351121902466
    "RISK6"   1    -.03924537  .32  3.123263 1.5537894     -.00153553   -.05803723     .02032739  .00224152    -.04152244           .1512187          .64037025
    "RISK7"   1     .00169465   .8 2.5525958 1.4523403      .00679172   -.02243384     .01733677  .00136161     .01708998          .19683923          .76919919
    "RISK8"   1    .046523666   .5 2.8003268 1.7254468    .0097302483   .046617275  -.0098238577 .000312258    .054293247  .2602007985115051   .968187689781189
    "RISK9"   1    -.02459602  .56  3.037949 1.5474993        .006332   -.03046454    -.00046347  .00242492    -.03074603          .29088819          1.1118575
    "RISK10"  1   .0083292723 1.68 2.7440192 2.4694844     .005142555   .014554465   -.011367747 .000105064    .027739889 .39519748091697693 1.3198615312576294
    "RISK11"  1    .016329546  .92  2.640546 1.8393279     .012813671  .0041691546 -.00065327998 .000311274  -.0059106029 .17715220153331757  .7320494651794434
    "RISK12"  1    .050323751  .95 2.5809444  1.821951     .006365718   .033987419   .0099706144 .000312376    .063340943 .21709080040454865  .8568617701530457
    "RISK13"  1 -.00083573872 1.09 2.5919472  2.169208   -.0021443864   .015922061   -.014613413 .001666782  -.0018674647  .2722056210041046  1.013303518295288
    "RISK14"  1    .029093192  .72 2.7298375 1.3841688     .012083324  -.011895188    .028905056 .000883389    .026740776  .3178618252277374 1.1778684854507446
    "RISK15"  1    -.14767644  .13 2.0864168 2.3758314   -.0075564953   -.16234286    .022222913 .003233757    -.16637702 .42721113562583923 1.3929530382156372
    "RISK16"  1    -.26954779 1.72 2.4172208 2.5509157      .01020936   -.19496339   -.084793759   .0000723     -.1615685  .1622680276632309  .6432330012321472
    "RISK17"  1    .046534327  .53 2.6331611 1.3434119     .016018795   .011958005    .018557526   .0011034    .049530877 .21452780067920685   .765155017375946
    "RISK18"  1    .094060308 1.03 2.2325022 2.5078377    -.003344117    .10599931  -.0085948899 .001041301    .044683365  .2766834497451782  .8937629461288452
    "RISK19"  1    .013868882  .54 2.7243182 1.2076471     .016497021 -.0006471375  -.0019810008 .001158322  -.0018515328  .3375457525253296 1.1232787370681763
    "RISK20"  1    .024837474 -.29 3.0090558 1.4911677    .0013649322   .037841949   -.014369408 .003766778   .0096701738  .4162732660770416 1.3647109270095825
    end
    ------------------ copy up to and including the previous line ------------------

    Additionally I also created a id variable which nummerates all the portfolios with numbers from 1 to 45.

    Any ideas why am I getting the above message when using dhm function? Any help will much much appreciated!

    Last edited by Emilia Kosinska; 16 Jun 2019, 05:19.

  • #2
    It appears that the dhm command is part of the user-written clutils package described by
    Code:
    net describe clutils, from(http://teaching.sociology.ul.ie/statacode)
    (as the Statalist FAQ linked to from the top of the page asks you to tell us for commands that are not part of base Stata).

    The output of search mm_expand tells us that it is part of the user-written moremata package available from SSC. It is unfortunate that the documentation for the clutils installation does not advise you to install moremata as well, nor do the clutils commands like dhm check for its availability.

    You can install the moremata package from SSC by running
    Code:
    ssc install moremata
    Last edited by William Lisowski; 16 Jun 2019, 09:18.

    Comment


    • #3
      Thank you a lot, now the code works!

      Comment

      Working...
      X