Announcement

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

  • Confidence Interval with Graph Dot

    Dear all,

    I am trying to add confidence intervals to a graph dot showing the mean value of anti-immigrant attitudes for each country.

    Based on cross-sectional data including 28 countries, i generated the following example dataset consisting of the mean value of anti-immigrant attitudes for each country.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float antmi str2 cntry
     5.179465 "AT"
    4.4687862 "BE"
     5.980606 "BG"
     3.984998 "CH"
     5.756306 "CY"
     6.139078 "CZ"
     4.171445 "DE"
     4.239356 "DK"
     5.185469 "EE"
    3.9809716 "ES"
     3.886236 "FI"
     4.790751 "FR"
    4.1734457 "GB"
     4.947642 "HR"
     6.218821 "HU"
     3.810525 "IE"
    2.7447665 "IS"
     5.511042 "IT"
     4.952845 "LT"
     4.521533 "LV"
    4.1681414 "NL"
     3.972714 "NO"
     4.316811 "PL"
     3.811007 "PT"
     5.703016 "RS"
     3.627834 "SE"
     5.487343 "SI"
     6.264863 "SK"
    end
    The graph dot attached shows the mean value of anti-immigrant attitudes (dots) over countries (categorial axis presented vertically) and is based on the following command
    Click image for larger version

Name:	Graph.jpg
Views:	3
Size:	172.6 KB
ID:	1618789


    Code:
    . graph dot antmi, over (cntry, sort(1)descending) ///
    >         yline (5.09, lcolor(gray) lpattern(dash)) ///
    >         ytitle ("Anti-Immigrant Attitudes over country")
    My question is, how to add confidence intervals to the graph dot for each country mean of anti-immigrant attitudes similar to the attached graph

    Click image for larger version

Name:	Design-based-mean-BMI-weighted-and-confidence-interval-for-each-country_W640.jpg
Views:	1
Size:	52.0 KB
ID:	1618790

    Source: Masood, M., Aggarwal, A. & Reidpath, D.D. Effect of national culture on BMI: a multilevel analysis of 53 countries. BMC Public Health 19, 1212 (2019). https://doi.org/10.1186/s12889-019-7536-0

    This post is related to a previous post: https://www.statalist.org/forums/for...ls#post1595946 (see #10)

    I would be very grateful for any help.

    Best regards
    Amelie

  • #2
    graph dot is a dead end, unfortunately. You need to switch to twoway rcap and scatter.

    Comment


    • #3
      Code:
      clear all
      set scheme s1mono
      
      // open example data
      // you can get it from  https://doi.org/10.4232/1.12312
      cd c:\temp\issp
      use ZA5950_v2-0-0.dta
      
      // create the anti immigration index
      local vars "V48 V49 V50 V51 V52 V53 V54 V55 V56"
      mvdecode `vars', mv(8=.a \ 9=.b)
      desc `vars'
      recode V48 V50 V52 V54 (5=1) (4=2) (2=4) (1=5)
      alpha `vars',item gen(anti_imi)
      
      // store the grand mean
      sum anti_imi, meanonly
      local grand = r(mean)
      
      // get the mean and its standard error of indey by country
      collapse (mean) anti_imi (semean) se=anti_imi, by(C_ALPHAN)
      
      // sort the countries by mean index
      // requires labmask, which you can install by typing search labmask
      // also see https://www.stata-journal.com/article.html?article=gr0034
      egen y = rank(-anti_imi)
      labmask y, val(C_ALPHAN)
      
      // create fuzy confidence intervals
      foreach lev of numlist 1 /25 {
          gen lb`lev' = anti_imi - invnormal(1-`lev'/200)*se
            gen ub`lev' = anti_imi + invnormal(1-`lev'/200)*se
          local bar `bar' rspike lb`lev' ub`lev' y, horizontal lcolor(%10) ||
      }
      twoway `bar' scatter y anti_imi, ///
           msymbol(s) mcolor(%50) msize(*.6) ///
           legend(off) ylab(1/37, val angle(0) labsize(small)) ///
           ytitle("") xline(`grand') name(fuzy, replace)
           
      // create conventional confidence intervals
      gen lb = anti_imi - invnormal(.975)*se
      gen ub = anti_imi + invnormal(.975)*se
      twoway rspike lb ub y, horizontal || ///
             scatter y anti_imi, msymbol(oh) ///
             legend(off) ylab(1/37, val angle(0) labsize(small)) ///
             ytitle("") xline(`grand')
      Click image for larger version

Name:	fuzy.png
Views:	1
Size:	74.3 KB
ID:	1618798
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	66.1 KB
ID:	1618799
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Dear Maarten Buis,
        Thank you so much. It works perfectly. You have helped me so much and I guess I would have never come up with that solution.
        So again many thanks and best regards
        Amelie

        Comment

        Working...
        X