Announcement

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

  • New version of dstat available on SSC

    A new version of dstat is available. For installation, type:

    Code:
    . ssc install dstat, replace
    dstat is a very general command for the estimation of a wide variety of summary statistics and distribution functions. For a list of changes since the last update see changes after 07nov2025 on https://github.com/benjann/dstat/. Some new features are as follows.
    • dstat summarize now has an at() option to compute conditional statistics.
    Code:
    . sysuse nlsw88, clear
    (NLSW, 1988 extract)
    
    . dstat summarize (mean median) wage, at(grade=10/18)
    
    Conditional statistics            Number of obs   =      2,244
                                      Condition       =      grade
    
    --------------------------------------------------------------
            wage | Coefficient  Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
    mean         |
              10 |   4.692721   .2402356      4.221614    5.163829
              11 |   5.688235   .3512727      4.999382    6.377089
              12 |   6.638048   .1593726      6.325515    6.950581
              13 |   8.315217   .4910102      7.352335    9.278099
              14 |   9.130599   .4990696      8.151912    10.10929
              15 |    9.88578   .6455681      8.619806    11.15175
              16 |   9.806044   .4052976      9.011246    10.60084
              17 |   10.43081   .4875015      9.474806    11.38681
              18 |   11.60784     .50493      10.61766    12.59802
    -------------+------------------------------------------------
    median       |
              10 |   4.203828   .2676516      3.678957    4.728698
              11 |   5.032206    .230795      4.579612      5.4848
              12 |   5.507244   .1082474      5.294968    5.719519
              13 |   6.843801   .3397835      6.177478    7.510123
              14 |   7.745568    .354447      7.050489    8.440646
              15 |   8.904991   .3692172      8.180948    9.629034
              16 |   8.542671   .3745201      7.808229    9.277113
              17 |   10.06441   .4661785      9.150227     10.9786
              18 |   10.59178   .3289128      9.946779    11.23679
    --------------------------------------------------------------
    • twoway dstat now supports dstat summarize if the at() option is specified.
    Code:
    . twoway dstat summarize (mean median) wage, at(grade=10/18) over(union)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	54.5 KB
ID:	1784492
    • A new order() option can be used to change how results are arranged. For example, by default, dstat summarize groups results by variables. Type order(statistics) to group results by statistics.
    Code:
    . dstat summarize (mean median) wage tenure
    
    Summary statistics                Number of obs   =      2,231
    
    --------------------------------------------------------------
                 | Coefficient  Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
    wage         |
            mean |   7.792448   .1220428      7.553118    8.031777
          median |   6.280193   .0977002        6.0886    6.471786
    -------------+------------------------------------------------
    tenure       |
            mean |    5.97785   .1166616      5.749073    6.206627
          median |   3.833333   .1224775      3.593151    4.073515
    --------------------------------------------------------------
    
    . dstat summarize (mean median) wage tenure, order(statistics)
    
    Summary statistics                Number of obs   =      2,231
    
    --------------------------------------------------------------
                 | Coefficient  Std. err.     [95% conf. interval]
    -------------+------------------------------------------------
    mean         |
            wage |   7.792448   .1220428      7.553118    8.031777
          tenure |    5.97785   .1166616      5.749073    6.206627
    -------------+------------------------------------------------
    median       |
            wage |   6.280193   .0977002        6.0886    6.471786
          tenure |   3.833333   .1224775      3.593151    4.073515
    --------------------------------------------------------------
    • Option qdef() supports additional quantile estimation methods, and the methods (17 in total) can now be selected by keywords.
    ben

  • #2
    Yet another update is now available. I added support for (diverging) stacked bar charts:

    Code:
    . webuse nhanes2f, clear
    
    . separate health, by(sex)
    
    . dstat proportion health?, over(agegrp) percent nocasewise
    
    . dstat graph, stack vertical flip values(5) mlabcolor(black) colors(cet d03, reverse) bylabels("Men" "Women")
    Click image for larger version

Name:	Graph1.png
Views:	1
Size:	51.5 KB
ID:	1784800

    Code:
    . dstat graph, stack diverging merge xline(0) colors(cet d03, reverse) coeflabels(health1 = "Men" health2 = "Women") legend(position(6) rows(1))
    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	40.8 KB
ID:	1784801

    ben


    Comment


    • #3
      Thanks for the update, Ben.

      I recently encountered a problem with the previous version of dstat that I'd not yet taken time to troubleshoot. But it appears that the same issue arises when I install the new version you published today.

      Can you advise? Thanks.


      Code:
      cap drop _all
      
      ssc install moremata, replace
      ssc install dstat, replace
      
      sysuse auto
      
      dstat cdf price
      Resulting in
      Code:
      . cap drop _all
      
      .
      . ssc install moremata, replace
      checking moremata consistency and verifying not already installed...
      all files already exist and are up to date.
      
      . ssc install dstat, replace
      checking dstat consistency and verifying not already installed...
      all files already exist and are up to date.
      
      .
      . sysuse auto
      (1978 automobile data)
      
      .
      . dstat cdf price
      moremata version 2.0.6 or newer is required; type ssc install moremata, replace
      (error occurred while loading dstat.ado)
      r(499);
      
      end of do-file
      
      r(499);
      The reason that
      Code:
      all files already exist and are up to date
      appears after the
      Code:
      ssc install dstat, replace
      command is that I'd already run the update before running the do file that produced this post's results.

      I'm running StataNow/SE 18.5 on a Mac running Sonoma 14.6.1.
      Last edited by John Mullahy; 12 Feb 2026, 06:27.

      Comment


      • #4
        What happens if you call mm_version()? It should be

        Code:
        . mata: mm_version()
          206
        If mm_version() returns error or a different value then something is wrong with your moremata installation. Possibly an old lmoremata.mlib file is lying aroud somewhere along the ado path. Type

        Code:
        . findfile lmoremata.mlib, all
        to see all instances of the file and then remove old copies. In any case, restarting Stata is also a good idea.

        ben

        Comment


        • #5
          Thanks for the update(s) Ben. The output in #1 and #2 is very nice, IMO. But FYI (and for the benefit of other readers), I just want to document that -adoupdate- failed to update to the most recent version when I tried it just now. I had to follow your advice in #1 to get the most recent version.

          Code:
          . adoupdate dstat, update
          note: ado update updates community-contributed files; type update to check for updates to official Stata.
          
          Checking status of specified packages:
          
            [300] dstat at http://fmwww.bc.edu/repec/bocode/d:
                  installed package is up to date
          
          (no packages require updating)
          
          . which dstat
          c:\ado\plus\d\dstat.ado
          *! version 1.5.6  23jan2026  Ben Jann
          
          . ssc install dstat, replace
          checking dstat consistency and verifying not already installed...
          
          the following files will be replaced:
              c:\ado\plus\d\dstat.ado
              c:\ado\plus\d\dstat.sthlp
          
          installing into c:\ado\plus\...
          installation complete.
          
          . which dstat
          c:\ado\plus\d\dstat.ado
          *! version 1.5.7  08feb2026  Ben Jann
          --
          Bruce Weaver
          Email: [email protected]
          Version: Stata/MP 19.5 (Windows)

          Comment


          • #6
            I had the same experience as Bruce

            Comment


            • #7
              I guess there is an issue with the pkg file on SSC. I'll drop Kit a note. ben

              Comment


              • #8
                According to Kit, all files on SSC are ok. Unclear what that problem is. In any case,

                . ssc install dstat, replace

                will do the trick.

                Comment

                Working...
                X