After a regression in Stata, I am trying to plot only the coefficients of the interaction terms.
I was unable to do this using the community-contributed command coefplot
.
Here is a reproducible example and my attempted solutions:
sysuse auto, clear
reg price foreign i.turn foreign#i.turn
*this plots all coefficients:
coefplot,
*this drops _cons and foreign but not i.turn
coefplot, drop(i.turn _cons foreign )
*variations with keep also do not work
coefplot, keep(foreign#i.turn )
Is there any other way to to this?
I have cross-posted this question on Statalist.
You just need to specify the interactions:
sysuse auto, clear
reg price foreign i.turn foreign#i.turn, coeflegend noheader
local coefinter 1.foreign#33.turn 1.foreign#34.turn 1.foreign#35.turn ///
1.foreign#36.turn 1.foreign#37.turn
coefplot, keep(`coefinter')
EDIT:
You can also get all non-zero coefficients as follows:
sysuse auto, clear
reg price foreign i.turn i.foreign#i.turn, coeflegend noheader
matrix A = e(b)
local namecol "`: colnames A'"
tokenize `namecol'
forvalues i = 1 / `=colsof(matrix(A))' {
local mv = A[1,`i']
if `mv' != 0 & strmatch("``i''" , "*#*") {
local coefinter `coefinter' ``i''
}
}
coefplot, keep(`coefinter')