Announcement

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

  • Displaying full variable names when using summarize

    Dear Statlist:

    My question is the title. My variables have a long name. Ideally, I would like to shorten them, but for various reasons I would like to keep them as it is.
    When I use the summarize command, the variables are shortend. I want it to display the full names. Any ideas?
    I recognize that this post may be duplicate of https://www.statalist.org/forums/for...me-of-variable
    Apologies if it is, but that post was not so helpful.
    My data looks like..

    . dataex pc_sep pc_sep_trind pc_sep_trmass pc_sep_quit pc_sep_rtvol pc_sep_rtearly pc_sep_rtdis pc_sep_rtother pc_sep_rif pc_sep_term pc_sep_death pc_sep_other pc_
    > sep_trind_within pc_sep_trmass_within

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(pc_sep pc_sep_trind pc_sep_trmass pc_sep_quit pc_sep_rtvol pc_sep_rtearly pc_sep_rtdis pc_sep_rtother pc_sep_rif pc_sep_term pc_sep_death pc_sep_other pc_sep_trind_within pc_sep_trmass_within)
    1.9200317 .10886777          0  .5443389 1.1381631            0  .01979414          0           0   .04948535  .05938242           0  5.670103         0
    2.9299364 1.2738854          0 1.0191083 .50955415            0          0  .12738854           0           0          0           0  43.47826         0
     2.880435  .4347826          0  .4891304  .7065217    .05434782          0          0           0    1.195652          0           0  15.09434         0
    2.5791326  .8206331          0  .2344666  1.524033            0          0          0           0           0          0           0  31.81818         0
    1.9588146  .6864222          0  .3515821  .8203583            0 .033484012          0           0           0 .066968024           0 35.042736         0
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
     3.276131 1.5600624          0  .3120125 1.4040562            0          0          0           0           0          0           0  47.61905         0
     1.849229 .48152795          0 .27111238  .9590094    .01213936  .02427872 .008092906           0   .03641808  .05665034           0 26.039387         0
    1.8737885  .5599828          0  .4092182  .7753608            0          0          0           0   .12922679          0           0  29.88506         0
     1.566265 .24096386          0 1.0843374 .24096386            0          0          0           0           0          0           0 15.384615         0
     4.347826         0          0  1.242236  1.242236      .621118          0          0           0     .621118    .621118           0         0         0
    2.0026703  .5340454          0  .2670227  .9345794            0  .13351135          0           0           0  .13351135           0 26.666666         0
     3.014887  .2094711          0  1.900202 .25435776            0          0          0           0    .6209322  .02992444           0  6.947891         0
    2.5061426  .5896806          0  .7862408  .7862408            0          0          0           0    .3439803          0           0  23.52941         0
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
    1.9810153  .6603384          0 .37144035  .8666942            0          0  .04127115           0           0  .04127115           0 33.333332         0
     .8130081         0          0         0         0            0          0          0           0    .8130081          0           0         0         0
     4.112782  .6842105          0 2.4285715  .8421053            0  .04511278          0           0   .04511278 .067669176           0 16.636198         0
    2.2721448  .4783463          0  .6406423 1.0677372            0 .008541898 .008541898           0   .04270949 .025625695           0  21.05263         0
     3.048017  .4175365  .04175365 .29227558  .5427975            0          0          0           0   1.7536534          0           0  13.69863  1.369863
    2.0233734  .5232862          0  .9244723  .5232862            0 .017442875          0           0  .017442875 .017442875           0  25.86207         0
     1.510574  .3776435          0  .6797583  .3776435     .0755287          0          0           0           0          0           0        25         0
    2.2157228  .4963219 .008862891  .3722414  1.214216            0 .035451565          0           0   .06204024  .02658867           0      22.4        .4
     5.394191  .6224067          0  .6224067  2.074689            0          0          0           0    2.074689          0           0 11.538462         0
    2.3474178         0          0  .9389671 1.4084507            0          0          0           0           0          0           0         0         0
     .9661836  .9661836          0         0         0            0          0          0           0           0          0           0       100         0
     3.405018 1.0752689          0 1.0752689  .3584229            0          0          0           0    .7168459  .17921147           0 31.578947         0
    2.1067417 .28089887          0  .4213483  1.264045            0          0          0           0   .14044943          0           0 13.333333         0
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
     1.768173 .34758955          0  .6347287  .6649539            0          0          0           0   .10578812  .01511259           0  19.65812         0
     1.939462 .13452914          0  .1233184 1.4910314            0 .022421524  .15695067           0           0 .011210762           0  6.936416         0
     1.977894  .6399069          0  .4653869  .6980803            0          0          0           0   .17452008          0           0  32.35294         0
    1.4852014 .10684902          0  .8975318 .19232824            0          0          0           0   .28849235          0           0  7.194244         0
    1.0152284  .5076142          0         0  .5076142            0          0          0           0           0          0           0        50         0
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
    2.2950819         0          0  .8196721  .8196721            0          0          0           0    .6557377          0           0         0         0
    1.7784964 .11317704          0  .6413366   .576664            0 .005389383          0           0    .4149825 .026946915           0  6.363636         0
     3.440233 .16034986          0 1.7565597  .6049563            0 .036443148          0   .02915452    .7944607  .05830904           0  4.661017         0
    1.8052282   .133919  .00535676  .6320977  .7285194            0          0          0           0   .27319476  .03214056           0  7.418397  .2967359
     2.602816 .12041496          0  .4909226  .8706928            0  .00926269          0           0   1.0744721  .03705076           0 4.6263347         0
    2.1978023  .2354788          0  .8634223 1.0204082            0          0          0           0           0  .07849293           0 10.714286         0
    1.5416498   .197129          0 .22240195  .9401537            0  .01516377   .1566923           0           0  .01010918           0 12.786885         0
    1.0278802 .03397951          0  .2208668  .6778913            0 .020387705  .02718361           0   .01529078 .032280535           0  3.305785         0
     1.483595 .25677603          0  .6276748  .4564907            0          0          0           0   .05706134    .085592           0 17.307692         0
    1.8324608 1.0471205          0  .2617801  .2617801            0          0   .2617801           0           0          0           0  57.14286         0
     1.894452  .4330176          0  .4871448  .8660352            0          0          0           0    .0811908   .0270636           0 22.857143         0
     10.46147   .436828          0  .6160395  1.265681            0          0 .011200717           0     8.12052 .011200717           0  4.175589         0
     2.962963 .11904762          0  .7804233  .7671958   .026455026          0  .06613757  .013227513   1.1507937  .03968254           0  4.017857         0
     23.64498 .26580375 .017335027  1.248122 1.0401016            0 .034670055 .011556686           0    20.98694   .0404484           0 1.1241447 .07331378
    1.7766497  .4713561          0  .5076142  .7070341            0 .072516315          0           0  .018129079          0           0 26.530613         0
     9.749493  .1760325          0  5.836154  .4468517            0          0          0           0    3.263372 .027081924           0 1.8055556         0
    1.3173615 .11787757  .00159294   .398235  .6515125     .0318588  .03823056  .00318588           0    .0238941  .05097408           0  8.948005 .12091898
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
    1.6393442         0          0 1.6393442         0            0          0          0           0           0          0           0         0         0
    1.8450185  .3690037          0  .3690037  .7380074            0          0          0           0           0   .3690037           0        20         0
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
    1.4705882  .3151261          0  .5252101  .6302521            0          0          0           0           0          0           0  21.42857         0
    1.3292433  .7157464          0 .51124746 .10224949            0          0          0           0           0          0           0  53.84615         0
    2.3076923         0          0         0 2.3076923            0          0          0           0           0          0           0         0         0
      1.36123 .20166373          0 .23947567  .8444669            0  .05041593          0           0           0 .025207967           0 14.814815         0
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
            .         .          .         .         .            .          .          .           .           .          .           .         .         .
    1.5229082    .17208          0  .6539041  .5979781            0 .034416005          0           0 .0043020006    .060228           0 11.299435         0
      1.62559  .4195071          0  .8390142 .26219192            0  .05243839          0           0           0  .05243839           0  25.80645         0
     1.841489 .11407453 .002037045   .951009  .5191555 .00029100644 .034920774  .00407409           0   .17780493  .03753983 .0005820129   6.19469 .11061947
      3.06611 .22410105          0  .9677091  1.762249            0 .030559234          0           0  .030559234  .05093206           0   7.30897         0
     3.413401 1.8963338          0  .8849558   .505689            0          0          0           0           0  .12642226           0  55.55556         0
     5.524554 .55803573          0  .6138393  .7254464     .2232143          0          0           0   3.3482144  .05580357           0  10.10101         0
     3.605769  .3605769          0  .1201923  2.644231     .2403846          0   .1201923           0    .1201923          0           0        10         0
            2  .7731093          0   .487395  .6386555            0 .016806724          0           0   .05042017 .033613447           0  38.65546         0
      3.24575  .7727975          0  1.236476  1.236476            0          0          0           0           0          0           0 23.809525         0
    2.1878552  .5763923          0 .33284625 1.0756617     .0202955   .0527683 .008118201 .0040591005   .04870921  .06900471           0 26.345083         0
     2.523183  .6901014          0  .8194954  .8410611            0  .10782833          0           0   .04313134  .02156567           0  27.35043         0
    2.0432692  .9615384          0  .6009616  .4807692            0          0          0           0           0          0           0  47.05882         0
    3.7974684  .6329114          0 1.8987342  .6329114            0          0          0           0           0   .6329114           0 16.666666         0
            2 .13333334          0       1.2  .6666667            0          0          0           0           0          0           0  6.666667         0
     2.644736  .1666546          0 1.7462503  .2536048            0 .014491703          0           0    .4492428 .014491703           0   6.30137         0
     2.432969   .695134          0  .5461768  .9433962            0  .04965243          0           0   .19860972          0           0  28.57143         0
     2.777778  .7936508          0 1.1904762  .3968254            0          0          0           0    .3968254          0           0  28.57143         0
    2.1170611   .581154          0    .41511  1.079286            0    .041511          0           0           0          0           0  27.45098         0
    1.6393442         0          0         0 1.6393442            0          0          0           0           0          0           0         0         0
     3.833914  .8561903          0 2.2200334  .6364601            0  .06819215 .007576906           0  .007576906  .03788453           0 22.332016         0
     2.278394  .6448285          0 .57604676  .9371507            0  .02579314          0           0   .05158628  .04298856           0  28.30189         0
    2.2794428  .9286619          0 .25327143 .42211905            0   .0422119          0           0    .6331785          0           0  40.74074         0
    2.3543775  .8894315          0  .7673526  .5057551   .034879666  .12207883          0           0  .034879666          0           0  37.77778         0
    2.0973783 .52434456          0 .52434456  .8988764            0          0          0           0   .07490636  .07490636           0        25         0
    2.2955523  .6007891 .008967001  .3497131 1.2464132            0 .035868004          0           0  .035868004 .017934002           0 26.171875   .390625
     3.966597  .8350731          0  1.461378 1.2526096            0          0          0           0    .4175365          0           0  21.05263         0
     2.830189  .4716981          0 1.4150944  .9433962            0          0          0           0           0          0           0 16.666666         0
    1.4492754         0          0  .4830918  .9661836            0          0          0           0           0          0           0         0         0
    2.3809524 1.2820513          0  .3663004  .5494506            0          0          0           0    .1831502          0           0  53.84615         0
     1.810585 .27855152          0  .4178273  .9749303            0          0          0           0           0  .13927576           0 15.384615         0
      6.20155  .7751938          0 1.5503876 3.2945735     .3875969          0          0           0   .19379845          0           0      12.5         0
     2.857143         0          0  2.857143         0            0          0          0           0           0          0           0         0         0
    1.9721755  .4280691          0  .9478673  .4892218            0 .030576365          0           0  .015288183  .06115273           0  21.70543         0
     1.319797 .15792443          0 .18048505  .9024253            0          0  .05640158           0           0  .02256063           0 11.965812         0
    1.6129032 .10080645          0 .10080645 1.2096775            0  .10080645          0           0   .10080645          0           0      6.25         0
    2.0325203  .5226481          0  .6387921  .8130081            0  .05807201          0           0           0          0           0 25.714285         0
    2.0012128  .3638569 .030321406  .5761067  .9399636            0 .030321406          0           0  .030321406 .030321406           0 18.181818 1.5151515
     4.205346  .1789509          0 1.8454312 .20131977            0 .022368863          0           0    1.923722 .033553295           0  4.255319         0
    end
    ------------------ copy up to and including the previous line ------------------

  • #2
    Maybe create a collapsed data set?

    Code:
    * Test
    sum *
    
    * Reshape
    rename * x*
    gen id = _n
    reshape long x, i(id) j(name, string)
    * Collapse
    collapse (count) Obs = x ///
             (mean) Mean = x ///
             (sd) Std_dev = x ///
             (min) Min = x ///
             (max) Max = x, by(name)
    * Check again
    list
    Results from summarize:
    Code:
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
          pc_sep |         92    2.767845    2.661148   .8130081   23.64498
    pc_sep_trind |         92     .457605    .3642828          0   1.896334
    pc_sep_trm~s |         92    .0012633     .005752          0   .0417536
     pc_sep_quit |         92     .788371    .7734445          0   5.836154
    pc_sep_rtvol |         92    .8347714     .538541          0   3.294574
    -------------+---------------------------------------------------------
    pc_sep_rte~y |         92    .0187838    .0827625          0    .621118
    pc_sep_rtdis |         92    .0173283    .0283974          0   .1335113
    pc_sep_rto~r |         92    .0116994    .0401017          0   .2617801
      pc_sep_rif |         92    .0005048    .0033446          0   .0291545
     pc_sep_term |         92    .5949156    2.379768          0   20.98694
    -------------+---------------------------------------------------------
    pc_sep_death |         92    .0425957    .1008816          0   .6329114
    pc_sep_other |         92    6.33e-06    .0000607          0    .000582
    pc_sep_tri~n |         92    19.92595    16.81675          0        100
    pc_sep_trm~n |         92    .0464916    .2200456          0   1.515152
    Collapsed data:
    Code:
         +------------------------------------------------------------------------+
         |                 name   Obs       Mean    Std_dev        Min        Max |
         |------------------------------------------------------------------------|
      1. |               pc_sep    92   2.767845   2.661148   .8130081   23.64498 |
      2. |         pc_sep_death    92   .0425957   .1008816          0   .6329114 |
      3. |         pc_sep_other    92   6.33e-06   .0000607          0    .000582 |
      4. |          pc_sep_quit    92    .788371   .7734445          0   5.836154 |
      5. |           pc_sep_rif    92   .0005048   .0033446          0   .0291545 |
         |------------------------------------------------------------------------|
      6. |         pc_sep_rtdis    92   .0173283   .0283974          0   .1335113 |
      7. |       pc_sep_rtearly    92   .0187838   .0827625          0    .621118 |
      8. |       pc_sep_rtother    92   .0116994   .0401017          0   .2617801 |
      9. |         pc_sep_rtvol    92   .8347715    .538541          0   3.294574 |
     10. |          pc_sep_term    92   .5949156   2.379768          0   20.98694 |
         |------------------------------------------------------------------------|
     11. |         pc_sep_trind    92    .457605   .3642828          0   1.896334 |
     12. |  pc_sep_trind_within    92   19.92595   16.81675          0        100 |
     13. |        pc_sep_trmass    92   .0012633    .005752          0   .0417536 |
     14. | pc_sep_trmass_within    92   .0464916   .2200456          0   1.515152 |
         +------------------------------------------------------------------------+

    Comment


    • #3
      In Stata 17 and later, you can do the following:

      Code:
      local vars pc_sep - pc_sep_trmass_within
      qui table (var) , stat(count `vars') stat(mean `vars') stat(sd `vars') stat(min `vars') stat(max `vars')
      collect label levels result count "Obs" min "Min" max "Max" mean "Mean" sd "Std. dev.", modify
      collect preview
      which produces:
      Code:
      . collect preview
      
      ------------------------------------------------------------------------
                           |  Obs       Mean   Std. dev.        Min        Max
      ---------------------+--------------------------------------------------
      pc_sep               |   92   2.767845    2.661148   .8130081   23.64498
      pc_sep_trind         |   92    .457605    .3642828          0   1.896334
      pc_sep_trmass        |   92   .0012633     .005752          0   .0417536
      pc_sep_quit          |   92    .788371    .7734445          0   5.836154
      pc_sep_rtvol         |   92   .8347714     .538541          0   3.294574
      pc_sep_rtearly       |   92   .0187838    .0827625          0    .621118
      pc_sep_rtdis         |   92   .0173283    .0283974          0   .1335113
      pc_sep_rtother       |   92   .0116994    .0401017          0   .2617801
      pc_sep_rif           |   92   .0005048    .0033446          0   .0291545
      pc_sep_term          |   92   .5949156    2.379768          0   20.98694
      pc_sep_death         |   92   .0425957    .1008816          0   .6329114
      pc_sep_other         |   92   6.33e-06    .0000607          0    .000582
      pc_sep_trind_within  |   92   19.92595    16.81675          0        100
      pc_sep_trmass_within |   92   .0464916    .2200456          0   1.515152
      ------------------------------------------------------------------------

      Comment


      • #4
        @Hemanshu Kumar Extremely helpful. Thanks!

        Comment


        • #5
          Fsum will also work for this.

          Comment


          • #6
            Yes, that's a great suggestion! It is helpful to explain though, that fsum is a community-contributed command available via
            Code:
            net install fsum.pkg
            (See Statalist FAQ #12.1)

            Also note that Stata commands are case-sensitive, so Fsum will not work; fsum will.
            Last edited by Hemanshu Kumar; 24 Jul 2025, 07:23.

            Comment

            Working...
            X