Announcement

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

  • Sorting CIs in a ciplot command

    Hi,

    I want to plot the CIs for a proportion by country. It would be useful if I could display the CIs in ascending or descending order. I tried to use the sort command but apparently it wasn't possible to use it with ciplot.

    Is there a way around it?

    ciplot camh002_, by (country)

    - where camh002 is a binary variable
    - there are 27 countries

    Thank you

  • #2
    ciplot is from SSC. The help says this


    (note added August 2011)

    For fuller flexibility, consider using statsby first and then standard graphics commands (Cox 2010).


    Over a decade now, I've sometimes had difficulty in getting people to believe me.


    Here is a complete reproducible example. Once I'd started, I had to finish to make it clear why one industry has such a large confidence interval.


    Code:
    sysuse nlsw88, clear
    statsby , by(industry) : ci mean wage
    sort mean
    gen order = _n
    * labmask is from Stata Journal
    labmask order, values(industry) decode
    set scheme s1color
    gen where = 47
    scatter order mean || scatter order where, ms(none) mla(N) mlabsize(medsmall) mlabpos(9) xmla(45 "{it:n}", labsize(medsmall) labc(orange_red) tlc(none)) || ///
    rcap ub lb order, horizontal ytitle("") yla(1/`=_N', noticks ang(h) valuelabel) ///
    xsc(alt) xla(-10(10)40, grid) t1title(95%  confidence intervals for mean wage in USD/hr) legend(off)
    Click image for larger version

Name:	notaciplot.png
Views:	1
Size:	66.4 KB
ID:	1594784

    Last edited by Nick Cox; 23 Feb 2021, 18:56.

    Comment


    • #3
      The example was just plucked out of the air but sleeping on it convinced that the geometric means make more sense:


      Code:
      sysuse nlsw88, clear
      statsby N=r(N_pos) gmean=r(mean_g) ub=r(ub_g) lb=r(lb_g), by(industry) : ameans wage
      sort gmean
      gen order = _n
      * labmask is from Stata Journal 
      labmask order, values(industry) decode
      set scheme s1color 
      gen where = 51
      scatter order gmean || scatter order where, ms(none) mla(N) mlabsize(medsmall) mlabpos(9) xmla(49 "{it:n}", labsize(medsmall) labc(orange_red) tlc(none)) || ///
      rcap ub lb order, horizontal ytitle("") yla(1/`=_N', noticks ang(h) valuelabel) ///
      xsc(alt) xla(0(10)40, grid) t1title(95% CIs for geometric mean wage in USD/hr) legend(off)

      The code is disingenuous. It's not obvious before trying out that 49 and 51 and 0(10)40 are fair choices

      Comment

      Working...
      X