Announcement

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

  • Coefplot main coefficient with two dimensions of grouping

    I want to plot the main coefficient from OLS and IV model with three different types of covariates, so that each covariate will get a different color close to each other while the different models are offset the way normally different coefficients would be. In the example below the Y-Axis would be OLS and IV, while the colours would be three different for each cov.

    Click image for larger version

Name:	coefplot.PNG
Views:	1
Size:	8.9 KB
ID:	1770801


    Any idea how to achieve that?

    Here is an MWE for the estimates

    Code:
     
     sysuse auto.dta  global cov1 foreign global cov2 $cov1 gear_ratio global cov3 $cov2 displacement  estimates clear forval j = 1(1)3 {     reg price mpg ${cov`j'}     estimates store ols`j'          ivreg price mpg ${cov`j'}     estimates store iv`j'     }

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12).

    Code:
    sysuse auto, clear  
    estimates clear
    reg price mpg foreign gear    
    estimates store ols          
    ivreg price mpg foreign gear    
    estimates store iv    
    coefplot (ols iv, keep(mpg) aseq) ///
             (ols iv, keep(foreign) aseq) ///
             (ols iv, keep(gear_ratio) aseq), ///
             eqlabel(OLS IV, angle(vert)) nokey
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	35.6 KB
ID:	1770811

    Comment


    • #3
      That's exactly the thing I am struggling with. I don't want the Y-Axis to be different coefficients from one model, but each time it should be the coefficient on mpg, but estimates using different types of covariates.

      Comment


      • #4
        Terminologies differ, but I understand 'covariate' to mean independent variable or regressor. In the regression:

        reg price mpg foreign gear
        "mpg" is a covariate. So your statement does not make full sense to me. If you want to order coefficients by regressors, consider the following where the position defines 1 "OLS" 2 "IV". You can specify colors as you wish.


        Code:
        sysuse auto, clear   
        estimates clear 
        reg price mpg mpg foreign gear    
        estimates store ols          
        ivreg price mpg foreign gear   
        estimates store iv     
        coefplot (ols, keep(mpg) aseq(mpg) offset(-.1)) ///
                 (iv, keep(mpg) aseq(mpg) offset(.1)) ///
                 (ols, keep(foreign) aseq(foreign) offset(-.1)) /// 
                 (iv, keep(foreign) aseq(foreign) offset(.1)) /// 
                 (ols, keep(gear_ratio) aseq(gear) offset(-.1)) ///
                 (iv, keep(gear_ratio) aseq(gear) offset(.1) ), nokey

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.4 KB
ID:	1770825

        Comment


        • #5
          Thanks for your patience!

          I had hoped that the the MWE makes it clearer. The "covariates" are the the different cov globals I use in the loop below. Still, each time I want to use only the coefficient of mpg in the regression.

          Code:
          sysuse auto.dta    
          global cov1 foreign  
          global cov2 $cov1 gear_ratio  
          global cov3 $cov2 displacement  
          
          estimates clear  
          
          forval j = 1(1)3 {      
          reg price mpg ${cov`j'}    
          estimates store ols`j'          
          
          ivreg price mpg ${cov`j'}      
          estimates store iv`j'    
          }

          Comment


          • #6
            Pretty much the same approach:

            Code:
            sysuse auto.dta    
            global cov1 foreign  
            global cov2 $cov1 gear_ratio  
            global cov3 $cov2 displacement  
            
            estimates clear  
            
            forval j = 1(1)3 {      
            reg price mpg ${cov`j'}    
            estimates store ols`j'          
            
            ivreg price mpg ${cov`j'}      
            estimates store iv`j'    
            }
            
              
            coefplot (ols1, keep(mpg) aseq(cov1) offset(-.1)) ///
                     (iv1, keep(mpg) aseq(cov1) offset(.1)) ///
                     (ols2, keep(mpg) aseq(cov2) offset(-.1)) ///
                     (iv2, keep(mpg) aseq(cov2) offset(.1)) ///
                     (ols3, keep(mpg) aseq(cov3) offset(-.1)) ///
                     (iv3, keep(mpg) aseq(cov3) offset(.1)), ///
                     nokey swapnames
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	29.7 KB
ID:	1770840

            Comment


            • #7
              Thanks!

              Comment

              Working...
              X