Announcement

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

  • marginsplot ci mlabel

    Dear Statalister.

    I want add confidence interval lower/upper value on marginsplot.

    To be more specific, I want to add [3.324] and [3.823] beside CIplot on bar(X=1) .

    Is it possible? How can I do this?

    My do file is

    qui:reg Y i.X
    margins X
    marginsplot, plot1opts(mlabel(_margin) mlabpos(1) mlabcolor(black) mlabformat(%9.3f)) ///
    title("X on Y") xtitle("X") ytitle("Y") ///
    recast(bar) plotopts(barw(.5)) ci1opt(color(black))


    | Delta-method
    | Margin std. err. t P>|t| [95% conf. interval]
    -------------+----------------------------------------------------------------
    X |
    1 | 3.57377 .1258284 28.40 0.000 3.324276 3.823265
    2 | 4.78125 .1737275 27.52 0.000 4.43678 5.12572
    3 | 2.777778 .3275838 8.48 0.000 2.12824 3.427316
    4 | 2.666667 .5673917 4.70 0.000 1.541634 3.7917
    5 | 3.2 .4394997 7.28 0.000 2.328553 4.071447


    Click image for larger version

Name:	test.png
Views:	1
Size:	19.2 KB
ID:	1730660

    Attached Files
    Last edited by Johnkim Kim; 18 Oct 2023, 00:21.

  • #2
    There is an -addplot()- option in marginsplot. Note the need of a reproducible example for any code suggestions (see FAQ Advice #12).

    Comment


    • #3
      Hi guys,

      I have a question regarding ploting of elasticities of individual cross sections in a single stata graph.

      reg lnTFP lnEU, robust
      margins, eyex(lnEU)
      marginsplot, xline(0) xtitle("name") ytitle("name")

      This command gives a elasticity plot with a confidence interval. However, how can I plot the elasticity for each of my cross-sections? I have 17 cross-sections. The cross-section variable is named as ID.

      Comment


      • #4
        Thank you Musau.

        Could you tell me how can I get [3.324] to mlabel value?

        For example, I get [3.574] by mlabel(_margin).

        Comment


        • #5
          In case you want code suggestions, #2 requests a reproducible example.

          Comment


          • #6
            I uploaded my data from the beginning. Please confirm "data1.dta" file and my do file.
            Now I upload "data1old.dta". It is stata 12 version.

            My do file is
            ​​​​​​​
            qui:reg Y i.X
            margins X
            marginsplot, plot1opts(mlabel(_margin) mlabpos(1) mlabcolor(black) mlabformat(%9.3f)) ///
            title("X on Y") xtitle("X") ytitle("Y") ///
            recast(bar) plotopts(barw(.5)) ci1opt(color(black))

            Help me please.
            Attached Files
            Last edited by Johnkim Kim; 20 Oct 2023, 11:12.

            Comment


            • #7
              You are almost there, except see the part that recommends using dataex to present data examples (FAQ Advice #12). With Stata 12:

              Code:
              *INSTALL DATAEX
              ssc install dataex, replace
              
              *LOAD YOUR DATASET
              use data1old.dta, clear
              dataex
              Then copy and paste the output here.

              Comment


              • #8
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float(X Y)
                5 4
                5 4
                5 3
                5 4
                5 3
                5 3
                5 3
                5 3
                5 4
                5 4
                5 3
                5 3
                5 3
                5 4
                5 4
                5 4
                5 4
                5 4
                4 3
                4 4
                4 3
                4 4
                4 4
                1 4
                1 2
                1 2
                1 4
                1 .
                1 3
                1 .
                1 2
                1 3
                1 4
                1 2
                1 3
                1 3
                1 3
                1 3
                4 3
                2 .
                1 4
                1 3
                1 4
                1 2
                1 3
                1 3
                5 .
                5 3
                5 4
                5 3
                5 4
                5 3
                5 3
                5 4
                5 3
                5 3
                5 4
                5 4
                5 3
                5 3
                5 .
                5 3
                5 4
                5 .
                5 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 3
                2 4
                2 4
                2 4
                2 4
                2 3
                2 4
                2 4
                2 2
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 4
                2 3
                2 4
                2 4
                5 3
                2 4
                1 4
                1 4
                1 4
                end

                qui:reg Y i.X
                margins X
                marginsplot, plot1opts(mlabel(_margin) mlabpos(1) mlabcolor(black) mlabformat(%9.3f)) ///
                title("X on Y") xtitle("X") ytitle("Y") ///
                recast(bar) plotopts(barw(.5)) ci1opt(color(black))

                ------------------------------------------------------------------------------
                | Delta-method
                | Margin std. err. t P>|t| [95% conf. interval]
                -------------+----------------------------------------------------------------
                X |
                1 | 3.136364 .1210796 25.90 0.000 2.895818 3.376909
                2 | 3.83871 .1020003 37.63 0.000 3.636068 4.041351
                4 | 3.5 .2318497 15.10 0.000 3.03939 3.96061
                5 | 3.485714 .0959949 36.31 0.000 3.295004 3.676425
                ------------------------------------------------------------------------------

                Margins result is different because this is not full data.

                I want add 95% lower/upper CI.
                For example if X=1 then (2.896, 3.377) add on graph.
                Thank you very much.
                Attached Files
                Last edited by Johnkim Kim; 22 Oct 2023, 20:11.

                Comment


                • #9
                  Thanks for the data example. Here is one approach:

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input float(X Y)
                  5 4
                  5 4
                  5 3
                  5 4
                  5 3
                  5 3
                  5 3
                  5 3
                  5 4
                  5 4
                  5 3
                  5 3
                  5 3
                  5 4
                  5 4
                  5 4
                  5 4
                  5 4
                  4 3
                  4 4
                  4 3
                  4 4
                  4 4
                  1 4
                  1 2
                  1 2
                  1 4
                  1 .
                  1 3
                  1 .
                  1 2
                  1 3
                  1 4
                  1 2
                  1 3
                  1 3
                  1 3
                  1 3
                  4 3
                  2 .
                  1 4
                  1 3
                  1 4
                  1 2
                  1 3
                  1 3
                  5 .
                  5 3
                  5 4
                  5 3
                  5 4
                  5 3
                  5 3
                  5 4
                  5 3
                  5 3
                  5 4
                  5 4
                  5 3
                  5 3
                  5 .
                  5 3
                  5 4
                  5 .
                  5 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 3
                  2 4
                  2 4
                  2 4
                  2 4
                  2 3
                  2 4
                  2 4
                  2 2
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 4
                  2 3
                  2 4
                  2 4
                  5 3
                  2 4
                  1 4
                  1 4
                  1 4
                  end
                  
                  
                  qui:reg Y i.X
                  qui margins X, saving(myfile, replace)
                  preserve
                  merge 1:1 _n using myfile
                  format _ci_lb _ci_ub _m1 %4.3f
                  margins X
                  set scheme s1mono
                  marginsplot, plot1opts(mlabel(_margin) mlabpos(1) mlabcolor(black) mlabformat(%9.3f)) ///
                  title("X on Y") xtitle("X") ytitle("Y") ///
                  recast(bar) plotopts(barw(.5)) ci1opt(color(black)) leg(off) ///
                  addplot((scatter _ci_lb _m1, msy(none) mlab(_ci_lb)) (scatter _ci_ub  _m1, msy(none) mlab(_ci_ub)))
                  restore
                  Click image for larger version

Name:	Graph.png
Views:	1
Size:	22.7 KB
ID:	1731244

                  Comment


                  • #10
                    This is what I want.
                    Thank you very much.

                    Comment

                    Working...
                    X