Announcement

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

  • marginsplot with custom labels

    Is there a good way to fully replace the labels that marginsplot produces? I have a regression with a transformed regressor, and I want the labels that refer back to the original values. Consider something like

    Code:
    sysuse auto, clear
    gen inv_price = 1/price
    logit foreign inv_price
    cap noi margins, at( price = (2000 5000 10000) )
    margins, at( inv_price = (`=1/2000' `=1/5000' `=1/10000') )
    marginsplot
    Now I want the real price tags on my x-axis... or on axis(2) if I can add it... or on the top axis. Is that doable? In the very worst case, I can create the effect that I need with a long series of added text() that I can produce. But that looks like a somewhat inferior solution, given that the ugly labels are still going to be stuck on the x-axis.
    -- Stas Kolenikov || http://stas.kolenikov.name
    -- Principal Survey Scientist, Abt SRBI
    -- Opinions stated in this post are mine only


  • #2
    Is this like what you want? It requires the mcp (aka marginscontplot) command available from SSC. I can send some references and links to it if it seems to do what you want.

    Code:
    sysuse auto, clear
    gen inv_price = 1/price
    logit foreign inv_price
    sum price
    range w1 r(min) r(max) 20
    gen inv_w1 = 1/w1
    mcp price (inv_price), var1(w1 (inv_w1)) show
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Yes, more or less. Thanks, Richard.
      -- Stas Kolenikov || http://stas.kolenikov.name
      -- Principal Survey Scientist, Abt SRBI
      -- Opinions stated in this post are mine only

      Comment


      • #4
        Good. Some links:

        http://www.stata-journal.com/article...article=gr0056 (Royston's SJ article on the command)

        http://www3.nd.edu/~rwilliam/stats3/Margins03.pdf (My handout on the command)

        http://www.statalist.org/forums/foru...nuity-at-knots (see especially post 11. This shows how to work with spline functions)

        There are lots of options I didn't mention, e.g. add -ci- as an option if you want the confidence intervals.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        Stata Version: 17.0 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          All of the standard graphics options are available with marginsplot. Their documentation is hiding under the link to [G-3] twoway_options in the Syntax table and Option sections of the help and the PDF manual entry for marginsplot. So, Stas can use the standard xlabel() option to change the labels on his x-axis ticks any way he likes. Because one way of specifying axis labels is to give first the label location then the quoted text for the label, Stas's marginsplot command could be:

          Code:
          marginsplot , xlabel(`=1/2000' "2000" `=1/5000' "5000" `=1/10000' "10000")
          Now his x-axis labels will be 2000, 5000, and 10000. They will be in reverse order because the smallest tick location is 1/10000. Stas might also want to reverse order of the ticks and labels by adding the option xscale(reverse)​. He can also improve the axis title with something like xtitle(Price).

          Comment


          • #6
            Thanks, Vince. I was not aware of the xlabel( # "text" ) functionality. This is a more elegant and less complicated solution.
            -- Stas Kolenikov || http://stas.kolenikov.name
            -- Principal Survey Scientist, Abt SRBI
            -- Opinions stated in this post are mine only

            Comment


            • #7
              Hi,

              Thanks for the postings. I have a related question about custom label with marginsplot. multianalys10_w4y-cardrsk_plot.gph

              I am trying to set up something like this:

              marginsplot, recast(line) recastci(rarea) ytitle("Cardiovascular Risk Index") ///
              xtitle("Longtidinal Obesity") xlabel (`=none' "none" `=obese@adulthd' "@adult" `obese@early-adlt' "@early-adult" `=obese@adolsct' "@adolescent")

              But it did not work. Do you know how I can fix it?

              multianalys10_w4y-cardrsk_plot.gph

              Thanks!

              Alice
              Attached Files

              Comment

              Working...
              X