Announcement

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

  • dstat can now be used on graph twoway

    The latest update of dstat now provides command twoway dstat that makes it possible to include dstat's distribution estimates (PDF, CDF, complementary CDF, histogram, proportions, quantiles, Lorenz curves, percentile shares, TIP curves) in two-way graphs. There are two syntax variants. Under syntax one, results are computed on the fly; syntax two can be used to plot existing estimates; the two syntax types can be combined in a single twoway command. For example, here is how you could print a histogram including error bars and overlay a kernel density estimate.

    Compute all results on the fly (syntax 1)
    Code:
    sysuse nlsw88, clear
    twoway (dstat    histogram tenure, ep n(sturges) lalign(center)) ///
           (dstat ci histogram tenure, ep n(sturges)) ///
           (dstat    pdf tenure, ll(0) pstyle(p2))
    Compute some results upfront and some on the fly (mix of syntax 1 and 2; "." selects the current/active estimates)
    Code:
    dstat histogram tenure, ep n(sturges)
    twoway (dstat    ., lalign(center)) ///
           (dstat ci .) ///
           (dstat    pdf tenure, ll(0) pstyle(p2))
    Compute all results upfront (syntax 2)
    Code:
    dstat histogram tenure, ep n(sturges)
    estimates store HIST
    dstat pdf tenure, ll(0)
    estimates store PDF
    twoway (dstat    HIST, lalign(center)) ///
           (dstat ci HIST) ///
           (dstat    PDF, pstyle(p2))
    All three examples produce the same graph, which looks about as follows.

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	35.3 KB
ID:	1783094


    Specifying multiple variables or sub-populations is supported:
    Code:
    twoway (dstat ci pdf tenure ttl_exp wage, ll(0)) ///
           (dstat    pdf tenure ttl_exp wage, ll(0) pstyle(p1 p2 p3) ///
               lpattern(l dash dash_dot) lwidth(medthick ..))
    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	54.5 KB
ID:	1783095


    Code:
    twoway dstat pdf tenure ttl_exp wage, ll(0) over(union)
    Click image for larger version

Name:	Graph3.png
Views:	1
Size:	65.2 KB
ID:	1783096


    Type
    Code:
    . ssc install dstat, replace
    to install the update. After that, type
    Code:
    . help twoway dstat
    for documentation. Stata version 16 or newer is required by twoway dstat.
Working...
X