3
votes

Suppose you want to make a plot of regression coefficients where interactions are both grouped and renamed. Following the example from the -coefplot- paper (Jann, 2014) the following code allows you to group the interactions:

* BEGIN *
sysuse auto, clear
keep if rep78>=3
//run regression
quietly regress mpg headroom i.rep78#i.foreign
eststo model
//plot results       
coefplot model, /// 
    xline(0) omitted baselevels ///
    headings( 3.rep78#0.foreign = "{bf:Interaction Effects}") /// 
    drop(_cons)
* END *

and the following allows you to rename an interaction (just one for the sake of brevity):

* BEGIN *
coefplot model, /// 
    xline(0) omitted baselevels ///
    rename( 3.rep78#0.foreign = "new name") /// 
    drop(_cons)
* END *

but combining the two methods

* BEGIN *
coefplot model, /// 
    xline(0) omitted baselevels ///
    rename( 3.rep78#0.foreign = "new name") ///     
    headings( 3.rep78#0.foreign = "{bf:Interaction Effects}") /// 
    drop(_cons)
* END *

does not produce the desired result.

For my data I make use of the groups() option as well, so I would like to find a solution where I can combine headings() and rename(). Any pointers are greatly appreciated.

1
@NickCox Is it bad form to cross-post? Wasn't sure. - invictus
It's bad form to cross-post within the SE system, not the issue here. It's (widely) considered good form to tell people about postings on forums outside SE, in this case Statalist. There are several discussions on Meta, and this is my summary. (For completeness, note that Statalist does have an explicit policy that you should tell people about cross-postings.) - Nick Cox
Duly noted, thank you. - invictus

1 Answers

3
votes

Use the coeflabels() option:

*----- example data -----

sysuse auto, clear
keep if rep78>=3

//run regression
quietly regress mpg headroom i.rep78#i.foreign
eststo model

*----- what you want -----

coefplot model, /// 
    xline(0) omitted baselevels ///
    coeflabels(3.rep78#0.foreign = "new name") /// 
    headings(3.rep78#0.foreign = "{bf:Interaction Effects}") ///
    drop(_cons)