Search code examples
stata

coefplot: Putting names of regressions on y-axis


The following code will generate a coefficient plot:

sysuse auto, clear
regress price mpg trunk length turn if foreign==0
estimates store D
regress price mpg trunk length turn if foreign==1
estimates store F
coefplot D F, drop(_cons) xline(0)

enter image description here

However, I want to put custom names for each stored regression set of results on the y-axis:

enter image description here

I tried various things about scale and label like xrescale but failed.


EDIT:

I do not mean to repeat Domestic and Foreign. I only want to keep trunk. All other coefficients are not necessary. So Domestic and Foreign will appear just once.


Solution

  • I think this is a terrible idea. If you keep repeating Domestic/Foreign, then there is no way for the reader to know which pair corresponds to each variable.

    Here's a better approach:

    sysuse auto, clear
    estimates clear 
    
    regress price mpg trunk length turn if foreign==0
    estimates store D
    
    regress price mpg trunk length turn if foreign==1
    estimates store F
    
    coefplot (D, asequation(Domestic) \ F, asequation(Foreign)), drop(_cons) xline(0) 
    

    enter image description here

    Alternatively:

    coefplot (D, asequation \ F, asequation), drop(_cons) xline(0) ///
    eqlabels("Domestic" "Foreign", asheadings)
    

    enter image description here


    EDIT:

    The only way you can achieve what you want is by using the following hack:

    coefplot D F, drop(_cons mpg length turn) ///
    coeflabels(trunk = `""Domestic -" " " " " " " " " " " " " " " "Foreign -""') ///
    ylabel(, notick labgap(0)) xline(0) legend(off)
    

    enter image description here

    You will obviously have to adapt it for your different use cases.