Announcement

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

  • Reformat Stata output with leading zeros and limited digits behind the decimal point

    Hi,

    I'm just running some regressions etc. with stata and I need some output in a specific format, in this case from the "summarize" command. I need leading zeros in front of each decimal point and behind it there must not be more than three digits. E.g. .0211623 should be 0.021. How can I achieve that? Please consider that I don't want to change the format of my underlying variables, I just want to transform this (and a some other) outputs without having to do all the work manually. Thank you in advance!

    Variable | Obs Mean Std. Dev. Min Max
    -------------+---------------------------------------------------------
    a90~a_cap_gr | 137 .0211623 .0194278 -.0430071 .079362
    rgdpe_cap_~i | 137 10910.97 12923.86 526.8798 103656.5
    a9008_csh_i | 137 .2081899 .072164 .0577531 .4482758
    lsc | 137 18.33182 12.99447 .5486215 57.8249
    a9008_csh_g | 137 .1810669 .0666296 .0144852 .3595401
    -------------+---------------------------------------------------------
    a9008_pop_gr | 137 .0152968 .0133042 -.0127386 .0751865
    a9008_open | 137 .5337351 .4990168 .0756112 3.907469
    a9008_pl_c~r | 137 .0316714 .0206363 -.034935 .0846746
    transition | 137 .1167883 .3223465 0 1
    dejure_index | 109 .6286496 .1413518 .2998106 .9341667
    -------------+---------------------------------------------------------
    dejure_ind~d | 93 .6271609 .158555 .15875 .9388889
    defacto_in~x | 106 .6310293 .2359425 .1333333 1
    defacto_in~d | 79 .5498823 .2471934 .08 1
    a7010_LJI | 109 .4805156 .2903928 .0088805 .9918708
    a7010juco~01 | 121 .5666316 .2703884 .0530244 .991
    -------------+---------------------------------------------------------
    a7010hcin~01 | 121 .1975028 1.321798 -2.78 3.012463
    a7010hcco~01 | 121 .4696151 1.284759 -2.818049 2.84
    a8110_dCI_01 | 119 .405608 .3984045 0 1
    a0010fra_02 | 62 5.88665 2.269804 .734152 9.104204

  • #2
    Assigning formats to your variables and using the format option on the summarize command seems to do what you want.
    Code:
    . summarize x y
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
               x |        100    .4860843    .2946112   .0034408   .9921945
               y |        100    5.253147    2.740814    .073346   9.979447
    
    . format x y %9.3f
    
    . summarize x y, format
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
               x |        100       0.486       0.295      0.003      0.992
               y |        100       5.253       2.741      0.073      9.979

    Comment


    • #3
      That worked, thank you!

      Comment

      Working...
      X