Announcement

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

  • stripplot group_options for excluding empty categories of over(var)

    Dear Stata Users,

    I am trying to reduce the gap between the categories of my over variable (Country). In the graph below I get a huge gap between Estonia Belgium and Belgium Sweden, because Estonia==2. Belgium==4, Sweden==6, The 2 countries with codes 3 and 5 have no data for variable distance2 and hence the gap. Is there a workaround in stripplot without having to recode the labels of the Country variable.

    Code:
    preserve
    local N = _N
    expand 2
    gen byte new = _n > `N'
    replace Country1 = 10 if new
    clonevar distance2 = distance
    replace distance2 = 4500 if distance2>4500
    gen outliers = distance > 4500
    
    stripplot distance2 if survey==3 , pctile(5) vertical box(barw(0.8)) center over(Country1) yla(0(1000)4000 4500 "outliers") ms(none) legend(off) separate(outliers) xla(1 "Italy" 2 "Estonia" 4 "Belgium" 6 "Sweden" 7 "Germany" 8 "Hungary" 9 "Spain" 10 "all")
    
    
    restore
    Thank you in advance.
    Attached Files
    Last edited by Rajini Nagrani; 11 Aug 2022, 02:26.

  • #2
    stripplot is from SSC, as you are asked to explain (FAQ Advice #12).

    One solution is map your codes to successive integers.


    Code:
    egen x = group(countrycode) if survey == 3 & distance2 < ., label
    and use x for the plot.

    But you could probably improve on the order you have. The order Italy, Estonia, Belgium, ... perhaps has a logic you can explain.

    Otherwise see the myaxis command from the Stata Journal as discussed at

    https://www.statalist.org/forums/for...e-or-graph-use

    https://journals.sagepub.com/doi/pdf...6867X211045582

    Comment


    • #3
      Dear Nick,

      Thank you so much for your prompt reply. I think I will go ahead with the egen code.

      Apologies for not mentioning my Stata version and command name. I will do this correctly in my next posts

      Comment

      Working...
      X