Announcement

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

  • Coefplot, changing formatting in stored results

    I'm trying to use coefplot to graph average predicted probabilities after a logit regression but without going into detail as to why, I need to report the results as percentages. Meaning I need to multiply the stored results by 100 and add a % for the label. The example below is not the data I'm working with but it is similar. Instead of showing 0.2408 for white, I'd like to show 24%
    Can someone help with this?
    Code:
    clear
    use https://www.stata-press.com/data/r16/lbw
    
    logistic low age4 lwt i.race i.smoke i.ptl i.ht i.ui
    margins i.race i.smoke i.ptl i.ht i.ui , post
    estimates store a
    coefplot a, title("Average Predicted Probability of Low Birth Weight", size(med.small)) xline(0)  omitted baselevels mlabel format(%9.4f) mlabposition(2) mlabsize(vsmall)
    Click image for larger version

Name:	GraphExample.jpg
Views:	3
Size:	42.4 KB
ID:	1707690

  • #2
    coefplot is from SSC (FAQ Advice #12).

    Code:
    clear
    use https://www.stata-press.com/data/r16/lbw
    
    logistic low age lwt i.race i.smoke i.ptl i.ht i.ui
    margins i.race i.smoke i.ptl i.ht i.ui , post
    estimates store a
    set scheme s1mono
    coefplot a, title("Average Predicted Probability of Low Birth Weight", ///
    size(med.small)) xline(0)  mlab(string(@b*100, "%3.0f")+"%") ///
    mlabposition(2) mlabsize(vsmall) omitted baselevels
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	68.9 KB
ID:	1707724

    Comment


    • #3
      thank you for the help.

      Comment


      • #4
        I greatly appreciate your help but when I try to run your code I get the following error
        "factor-variable and time-series operators not allowed"

        Comment


        • #5
          The exact code in #2 produces the uploaded figure. So if you adapted it to your problem, the error probably results from your adaptation. Therefore, show the exact and full code that you ran and the resulting error message. Post this within CODE delimiters. Note that

          size(med.small)
          should be

          Code:
          size(medsmall)
          [.] This error is transferred from your example in #1 but is just ignored and does not stop the command from executing.
          Last edited by Andrew Musau; 06 Apr 2023, 13:07.

          Comment


          • #6
            The code I ran is:
            HTML Code:
            clear
            use https://www.stata-press.com/data/r16/lbw
            
            logistic low age lwt i.race i.smoke i.ptl i.ht i.ui
            margins i.race i.smoke i.ptl i.ht i.ui , post
            estimates store a
            
            coefplot a, title("Average Predicted Probability of Low Birth Weight", ///
            size(small)) xline(0)  mlab(string(@b*100, "%3.0f")+"%") ///
            mlabposition(2) mlabsize(vsmall) omitted baselevels
            it resulted in the following error:
            HTML Code:
            factor-variable and time-series operators not allowed
            r(101);

            Comment


            • #7
              Again, as I said in #5, I am not able to replicate your error. So reposting the code instead of copying and pasting the output from the Results window does not help.

              1. Try updating coefplot.

              Code:
              ssc install coefplot, replace
              2. Copy and paste the code directly from #2 to a do-file. Perhaps you introduce invisible characters if copying the code and pasting somewhere else before copying again to the do-file.

              Comment


              • #8
                that's exactly what it was. I just needed to update coefplot. THANK YOU!!! And thank you for your patience with me.

                Comment

                Working...
                X