Announcement

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

  • Can I actually plot this using coefplot?

    Hi all,

    I am trying to have together the matching coefficients, but I do not manage to do so. For the following code I ran 4 regressions and stored their estimates.

    Code:
    coefplot model1 model2 model3 model4, ///
        keep(3.s1_sampledata_mode 2.s1_sampledata_mode) ///
        xline(0) ///
        title("Effect of Mode on Various Outcomes") swapnames
    Using this code, I get the following graph:


    Click image for larger version

Name:	Screenshot 2025-02-03 195135.png
Views:	1
Size:	80.2 KB
ID:	1772036



    However, although it is really close to what I want, I'd like to have the estimates for the models (the ones calles 2.s1_sample... and 3.s1_sample...) together one on top of the other instead of having first the estimates for one of the modes, and later repeating them again.

    I have looked into the coefplot documentation but my case does not seem to be addressed - so, is there a way to plot what I want on STATA?

    Thank you for your time.

  • #2
    You might want something like:

    Code:
    coefplot (model1 \ model2 \ model3 \ model4), aseq ///
        keep(3.s1_sampledata_mode 2.s1_sampledata_mode) ///
        xline(0) ///
        title("Effect of Mode on Various Outcomes")

    Comment


    • #3
      Brilliant! The code above is what I was exactly looking for.

      Now I get this:

      Click image for larger version

Name:	Screenshot 2025-02-04 084819.png
Views:	1
Size:	79.9 KB
ID:	1772065


      Two questions follow:

      a) Is there a way to assign one color to one of the modes and another color to the other?
      b) If so, is it possible too to simplify the X axis and keep only Model 1, Model 2, Model 3 and Model 4? With a two-color palette indicating in the legend which color belong to which mode.

      Thank you for your time.

      Comment


      • #4
        Up

        Comment


        • #5
          This might be one way to do it. I am using demo data since you did not provide any data example.

          Code:
          clear all
          sysuse nlsw88
          
          local depvars wage hours ttl_exp tenure
          
          forval i= 1/4 {
              local depvar: word `i' of `depvars'
              egen `depvar'_std = std(`depvar')
              eststo model`i': regress `depvar'_std ib3.race
          }
          
          coefplot    (model1 \ model2 \ model3 \ model4, keep(1.race) label("White") msymbol(O) mcolor(orange%60) ciopt(lcolor(orange%60))) ///
                      (model1 \ model2 \ model3 \ model4, keep(2.race) label("Black")  msymbol(D) mcolor(green%60) ciopt(lcolor(green%60))), ///
                      aseq ///
                      xline(0) ///
                      title("Effect of Race on Various Outcomes") ///
                      coeflabels(, nolabels noticks) ///
                      legend(pos(2) ring(0))
          this produces:

          Click image for larger version

Name:	Screenshot 2025-02-05 at 3.39.23 PM.png
Views:	1
Size:	972.0 KB
ID:	1772141

          Comment


          • #6
            Cannot stress how much I apreciate your help. Thank you, you solved all my doubts.

            Hope this post is informative for other users.

            Comment


            • #7
              I had run the Oaxaca Blinder decomposition. Also plot the coefficient of it, using coefplot commond (coefplot, drop(overall:group*) xline(0) ///
              > recast(bar) barwidth(.7) base(0) citop ciopts(recast(rcap)). But i don't want to prediction coefficient in it, because it making the plot largely scaled. I want to plot only explained ad unexplained difference and their covariates. Kindly help me with that. Thanks for your time and consideration.
              Last edited by Kumar Vijay; 24 Feb 2025, 10:33.

              Comment

              Working...
              X