0

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.

user42459
  • 883
  • 3
  • 12
  • 29

2 Answers2

1

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.

0

You can fully control what is being plotted using coefplot by adding the point-estimates and standard errors to their respective matrices. Here's an example where I iterately add the information I would like to plot to the matrices B and V. The labels for each coefficient contains some text, the point-estimate and the confidence intervals:

local group_age65l_label = "Age < 65"
local group_age65u_label = "Age >= 65"
local group_male_label = "Male"
local group_female_label = "Female"


matrix B = J(1,1,.)
matrix V = J(1,1,.)

local coeflabl_ = ""
local counter = 1
foreach var in group_age65l group_age65u group_male group_female {
    
    display "`var'"
    meologit mrs3 i.expos if `var' || megroup:, or
    matrix res = r(table)'
    matrix res = (res[2,1],res[2,4..6])
    
    local tmplab ="c`counter' = ?``var'_label'   " + string(res[1,1],"%12.2f") + " (" + string(res[1,3],"%12.2f") + ";" + string(res[1,4],"%12.2f") + ") ?"
    local coeflabl_ = "`coeflabl_' `tmplab'"
    
    matrix b = e(b)[1,2]
    matrix v = e(V)[2,2]
    matrix colname b = c`counter'
    matrix colname v = c`counter'
    matrix rowname v = c`counter'
    
    matrix zero = J(rowsof(V),1,0)
    matrix colnames zero = `: colnames v'
    matrix V = V , zero \ zero' , v
    matrix B = B , b
    local counter = 1 + `counter'
}
matrix B = B[1,2...]
matrix V = V[2...,2...]
ereturn post B V

global coeflabl_  = subinstr("`coeflabl_'","?",`"""',.)
coefplot, drop(_cons) xline(1) legend(off) format(%9.2g) scheme(sj) graphregion(color(white)) msymbol(D) msize(*0.5) mfcolor(white) mcolor(black) ciopts(lwidth(*0.5) lcolor(black)) ///
          coeflabels(${coeflabl_}, labsize(tiny) labgap(0)) yscale(range(0.39 1.60)) eform ///
          title("Odds ratio for shift in mRS at 90 days" "(RIC vs Sham-RIC)", size(small)) ///
          headings(c1 = "{bf: Age }" c3 = "{bf: Sex }")