Announcement

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

  • Graph showing 10 and 90th percentiles for multiple variables

    Hello everyone!
    I am trying to use a dot graph (or something else) to show the range between the 10th and 90th percentiles, separately for two years and two variables. The idea is to show inequality (or the difference between the 10th and 90th percentiles). I would like to do something like the code below, which does not work. Any suggestions would be much appreciated.


    graph dot (p10) adaF_1994 (p90) adaF_1994 , exclude0 noextendline linetype(line) ///
    (p10) adaF_2022 (p90) adaF_2022 , exclude0 noextendline linetype(line) ///
    (p10) adiF_1994 (p90) adiF_1994 , exclude0 noextendline linetype(line) ///
    (p10) adiF_2022 (p90) adiF_2022 , exclude0 noextendline linetype(line)


    Thanks,
    Arun

  • #2
    You can write custom code or you can use an existing command. This shows both. The existing command is stripplot from SSC and the price to pay is a thin median and quartiles box.


    Code:
    clear
    set obs 100 
    set seed 2803
    
    foreach v in adaF adiF { 
        foreach y in 1994 2022 {
            local i = `i' + 1 
            gen `v'_`y' = rnormal(`i', 1)
        }
    } 
    
    * start here 
    
    * from first principles 
    gen x = _n in 1/4 
    gen p10 = .
    gen p90 = . 
    
    tokenize adaF_1994 adaF_2022 adiF_1994 adiF_2022 
    
    quietly forval j = 1/4  { 
        su ``j'', detail
        replace p10 = r(p10) in `j'
        replace p90 = r(p90) in `j' 
        label def x `j' "``j''", modify 
    } 
    
    label val x x 
    
    twoway rspike p10 p90 x, xsc(r(0.5 4.5)) xla(1/4, valuelabel noticks) xtitle("") name(G1, replace)
    
    * existing command 
    stripplot ad?F_????, box(barw(0.1)) xla(, noticks) pctile(10) vertical ms(none) name(G2, replace)

    Comment


    • #3
      Nick Cox: Many thanks for the codes, they worked very well.

      Comment

      Working...
      X