Announcement

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

  • Changing ylabels to percentages

    How can I change the unit of y-axis in a marginsplot to percentages (i.e., multiplying them by 100)? I have a loop over a couple of variables and would like to do this change for all at once.

    Code:
    foreach fr in "labor_productivity" "debt" "icr" {
    margins, dydx(`fr') atmeans
    marginsplot
    }
    Click image for larger version

Name:	Untitled.png
Views:	1
Size:	11.3 KB
ID:	1757260

    Last edited by Hossein Jebeli; 26 Jun 2024, 15:44.

  • #2
    Maybe easier to change the units in margins rather than manipulate the marginsplot labels, although the latter is still possible.

    Code:
    foreach fr in labor_productivity debt icr{
        margins, dydx(`fr') atmeans expression(xb()*100)
        marginsplot
    }

    Comment


    • #3

      Thanks Andrew! My dataset is huge and predict(outcome(2)) was giving me the margins after an hour but if I use expression(predict(outcome(2))*100), it does not give me the margins even after a couple of hours.
      Code:
       foreach fr in labor_productivity debt icr{
          margins `fr', atmeans expression(predict(outcome(2))*100)    
      marginsplot }
      So is there a way to adjust the labels in marginsplot instead of using the expression in margins?

      P.S. I removed the dydx as I think the average at each level of `fr' is more informative in my case.

      Comment


      • #4
        Code:
        sysuse auto, clear
        mlogit rep78 mpg displ i.foreign
        margins foreign, predict(outcome(1)) 
        marginsplot
        marginsplot, plotopts(ylab(-.05 "-5" 0 .05 "5" .1 "10" .15 "15"))

        Comment


        • #5
          Thanks Andrew! I was hoping to find a way to do this automatically (as mentioned in the first post), because the margins are changing across variables and across different specifications that I am trying. But it seems this is the only way. Thanks.

          Comment


          • #6
            Try using the package -mylabels-
            Example here is for KM curve but might work with marginsplot.

            How Y-axis scale number represent as percentage (for Kaplan-Meier curve graph) - Statalist

            Comment

            Working...
            X