Announcement

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

  • Multiple Bars with 95% CI bar

    Hi Statalist,

    I always appreciate for your help. I am struggling with the confidence interval bar in the graph.

    I can successfully made a graph with the help of statalist yesterday, but the thing is that I need to display confidence interval in the graph.

    The graph I made is below with the following code.
    Click image for larger version

Name:	G4_2.png
Views:	1
Size:	19.8 KB
ID:	1572900


    Code:
    reg CasCov_a dNative if TipoComRev<=2 
    reg CasCov_b dNative if TipoComRev<=2
    
    gen id=_n
    reshape long CasCov_, i(id) j(which) string
    replace which= "CasCov_a" if which=="a"
    replace which= "CasCov_b" if which=="b"
    
    lab def com 0 "Campensino" 1 "Indigineous"
    lab val dNative com
    
    graph bar CasCov_ if TipoComRev<=2, over(dNative) ///
    over(which, relabel(1 "Case(all)"  2 "Case(confirmed)")) bgcolor(white) plotregion(fcolor(white)) ///
    graphregion(fcolor(white)) asyvars showyvars leg(off) ytitle("")


    What I need to show is as follows with the CI bar after the regression. If you can see, there is line for 95% CI.

    Click image for larger version

Name:	IMG_1494.jpg
Views:	1
Size:	328.8 KB
ID:	1572901




    I have been looking forward the command to show it, but coefplot (ssc) seems fine but I cannot find anything to show multiple variables by group in one chart.

    Could you let me know the way to draw the graph I showed?

    I attach the data below.

    Thank you so much for your help in advance.



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double UBIGEO float(CasCov_a CasCov_b dNative TipoComRev)
    1601070080 1 0 1 2
    1601070007 1 0 1 2
    1601070072 1 0 0 1
    1601100021 0 0 1 2
    1605040002 1 0 0 1
    1601070010 1 0 1 2
    1605050012 1 0 0 1
    1601070057 1 0 0 1
    1601070074 1 1 1 2
    1601060014 1 0 0 1
    1607060009 1 0 1 2
    2501010062 1 0 0 1
    1601070073 1 0 0 1
    1601050053 1 0 0 1
    1601070090 1 1 1 2
    1601070061 1 0 1 2
    2501050091 1 0 0 1
    1601070048 1 0 1 2
    1601070015 1 0 1 2
    1601060061 1 0 0 3
    1601070071 1 0 1 2
    1601070079 1 0 1 2
    1601060013 1 0 0 1
    1601070030 1 0 1 2
    1601060046 1 0 0 1
    1601070086 1 0 1 2
    1601070024 1 0 1 2
    1601070076 1 0 1 2
    2501030036 1 0 1 2
    1605060013 1 0 1 2
    1601070054 1 0 1 2
    1607060064 1 0 1 2
    1601070014 1 0 1 2
    1601070044 1 0 1 2
    1601100016 0 0 1 2
    1601070006 1 0 1 2
    1601070033 1 0 1 2
    2501040034 1 1 1 2
    2501010197 0 0 0 1
    1606020002 0 0 0 1
    1601100013 0 0 1 2
    2501050062 1 0 1 2
    1601070004 1 0 1 2
    2501050030 1 0 0 1
    1607060051 1 0 1 2
    2502030005 1 1 1 2
    2501010200 1 0 0 1
    1601060024 1 0 0 1
    1605060014 1 0 1 2
    1601040017 1 0 0 1
    1601070005 1 0 1 2
    1601060028 1 0 0 1
    2501040037 1 0 1 2
    1601060017 1 0 0 1
    2501030020 1 0 1 2
    2502030015 1 1 0 1
    1606050021 1 0 0 1
    2501040036 1 0 0 1
    1601070187 1 0 1 2
    2501040094 1 0 0 1
    2501070025 1 1 1 2
    2501050021 1 1 1 2
    1601060015 1 0 0 1
    1605060020 1 0 1 2
    1601080031 1 0 0 1
    2501040032 1 1 1 2
    1601060033 1 0 1 2
    2501050011 1 0 0 1
    1606020005 1 0 0 1
    1601060004 1 0 1 2
    2501010084 0 0 1 2
    1601100010 0 0 1 2
    2501070010 1 0 0 1
    1601070053 1 0 1 2
    1601060012 1 0 1 2
    2501040028 1 0 0 1
    1606050029 1 1 0 1
    1601060045 0 0 0 1
    2502030073 1 1 1 2
    2501040018 1 1 0 1
    2501010094 1 1 1 2
    1601060052 1 0 0 1
    1601060020 1 0 0 1
    1601070088 1 0 0 1
    1601050052 1 0 0 1
    1601060060 1 0 0 1
    1601070002 1 0 1 2
    2501040057 0 0 0 1
    2501040051 1 0 0 1
    1601070067 1 0 0 1
    1605060018 1 0 1 2
    1601070083 1 0 1 2
    2501040015 1 . 0 1
    2501030009 1 1 1 2
    1601060026 1 0 0 1
    2501040025 1 1 1 2
    1601080036 1 0 0 1
    1601070034 1 0 1 2
    2501040048 0 0 0 1
    1601080060 1 0 1 2
    end
    label values CasCov_a CasCov_a_label
    label def CasCov_a_label 0 "No", modify
    label def CasCov_a_label 1 "Si", modify
    label values CasCov_b CasCov_b_label
    label def CasCov_b_label 0 "No", modify
    label def CasCov_b_label 1 "Si", modify
    label values TipoComRev L_TipoCom
    label def L_TipoCom 1 "Campesino", modify
    label def L_TipoCom 2 "Nativa", modify
    label def L_TipoCom 3 "Colono", modify



  • #2
    Your code does absolutely nothing to pick up on any regression results. I wouldn't be surprised if you need to run coefplot after each model and then combine the graphs, but you should get better answers.

    Comment


    • #3
      Dear Nick,

      I appreciate that you pointed out the issue. Could you give me a hint to me about how to pick up the regression result and display the CI bar in the graph without using coefplot? Is there any way to do so?

      Comment


      • #4
        With coefplot, I got this for CosCav_a and CosCav_b. This is not close to what I want to get..

        Code:
        proportion CasCov_a if dNative==0 & TipoComRev<=2
        estimates store nativea
        
        proportion CasCov_a if dNative==1 & TipoComRev<=2
        estimates store campensinoa
        
        coefplot nativea campensinoa, vertical recast(bar) barwidth(0.3) fcolor(*.5) ///
         ciopts(recast(rcap)) citop citype(logit) format(%9.2f) /// 
         addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))
        
        proportion CasCov_b if dNative==0 & TipoComRev<=2
        estimates store nativeb
        
        proportion CasCov_b if dNative==1 & TipoComRev<=2
        estimates store campensinob
        
        coefplot nativeb campensinob, vertical recast(bar) barwidth(0.3) fcolor(*.5) ///
         ciopts(recast(rcap)) citop citype(logit) format(%9.2f) /// 
         addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))
        graph export coef2.png
        Click image for larger version

Name:	coef1.png
Views:	1
Size:	20.0 KB
ID:	1572911
        Attached Files

        Comment


        • #5
          I don't know what you want to show, but the mean of a proportion is not the same as either the intercept or the gradient from the kind of regression you showed in #1;

          Comment

          Working...
          X