Announcement

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

  • "Coefplot" - local characteristics of subgraphs

    Dear Statalist Members,

    I am using "coefplot" from Benn Jenn (http://repec.sowi.unibe.ch/stata/coefplot/), and plotting subgraphs by matrices. There are some unusual problems I can not resolve.

    The minimal working example (MWE) of my code is
    Code:
    sysuse auto, clear
    regress price mpg headroom trunk length turn if foreign==0
    matrix A = r(table)'
    matrix A = A[1...,"b"],A[1...,"ll"],A[1...,"ul"]
    matrix list A
    
    regress price mpg headroom trunk length turn if foreign==1
    matrix B = r(table)'
    matrix B = B[1...,"b"],B[1...,"ll"],B[1...,"ul"]
    matrix list B
    
    coefplot   (matrix(A), ci((2 3))), bylabel(Domestic)   ///
            || (matrix(B), ci((2 3))), bylabel(Foreign) ///
            ||, ///
            byopts(xrescale) ///
            xlabel(, grid glcolor(gs14) glwidth(vthin) labsize(small) format(%2.1f) )   ///
            ylabel(, noticks labsize(small))  ///
            graphregion(color(red) margin(1=-5 b=-4 r=0 t=0))
    Some unusual problems I can not resolve.
    1. The command "graphregion(color(_option) margin(_option))" is invaild.
    2. The command "ylabel(, noticks)" is invalid. It could not eliminate the ticks of y-axis.
    3. The method used to set different xscale of two subgraphs is invaild. Is there any command to achieve the setting?
    Code:
    coefplot (matrix(A), ci((2 3)) xscale(range(-2000,500)) ), bylabel(Domestic)  ///          
                  || (matrix(B), ci((2 3)) xscale(range(-2000,3000)) ), bylabel(Foreign)  ///        
                  ||, byopts(xrescale cols(2))
    The following demonstrates the result of using the code.


    I hope someone can help me. Thanks a lot.

    Best regards.
    Yifan

  • #2
    The command "graphregion(color(_option) margin(_option))" is invaild.
    Since the graph contains subgraphs, you need to specify graphregion() within byopts(). Yes, I agree this is confusing. coefplot uses graph's by() option to create the subgraphs and this is just how things are if the by() option is specified. The following should do:
    Code:
    coefplot   (matrix(A), ci((2 3))), bylabel(Domestic)   ///
            || (matrix(B), ci((2 3))), bylabel(Foreign) ///
            ||, ///
            xlabel(, grid glcolor(gs14) glwidth(vthin) labsize(small) format(%2.1f) )   ///
            ylabel(, noticks labsize(small))  ///
            byopts(xrescale graphregion(color(red) margin(1=-5 b=-4 r=0 t=0)))
    The command "ylabel(, noticks)" is invalid. It could not eliminate the ticks of y-axis.
    This is a bug in graph's by() option, I believe; it does not respect noticks. But you can specify tlstyle(none) or tlwidth(0) or tlength(0) instead of noticks to suppress the ticks.

    The method used to set different xscale of two subgraphs is invaild. Is there any command to achieve the setting?
    What do you mean by that? byopts(xrescale) does create different x-scales if I run your example.

    Comment


    • #3
      Dear Ben, Thanks for your suggestions. I will have a try for #1 and #2.

      For #3, the question is I could not set different xscale of two subgraphs by myself instead of the default using byopts(xrescale). Specifically, the default result is (-2000,1000),(-1000,2000). But if I want to change it to (-2000,500),(-1000,2500), what should I do? And here is the code according to a previous post.

      Code:
       coefplot (matrix(A), ci((2 3)) xscale(range(-2000,500)) ), bylabel(Domestic)  ///        
                  || (matrix(B), ci((2 3)) xscale(range(-2000,3000)) ), bylabel(Foreign)  ///                      
                  ||, byopts(xrescale cols(2))
      Thanks for your help.

      Last edited by Yifan Wang; 04 Jun 2019, 13:29.

      Comment


      • #4
        Ah, I see. This is not directly possible as graph's by() option has no such functionality. However, you can post-modify the graph using the addplot command (see ssc describe addplot). Some addplot examples can be found here: http://repec.sowi.unibe.ch/stata/coe...varia.html#h-3
        And here's an example closer to what you need:
        Code:
        sysuse auto
        regress price mpg trunk length turn
        estimates store Price
        regress weight mpg trunk length turn
        estimates store Weight
        coefplot Price || Weight, drop(_cons) xline(0) byopts(xrescale)
        addplot 1: , b1title("Dollars") xlabel(-500(100)200) norescaling
        addplot 2: , b1title("Pounds") xlabel(-75(25)50) norescaling

        Comment


        • #5
          Thank you a lot for the code. I run it and it looks great.

          Comment

          Working...
          X