3

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.

0

2 Answers 2

6

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')
Sign up to request clarification or add additional context in comments.

3 Comments

By the way, after regress you can also use margins 1.foreign#i.turn and then marginsplot to get the same graph.
do you envision a more automatic way to list the coefficients? I have several res, each of which is saved with eststo. I have 108 time periods, which get interacted with the treatment variable
It is not clear to me from your comment what you have. I think you may want to post a new question about this providing more details.
5

A solution a little bit easier than the one already proposed is to use wildcards ("*" or "?").

sysuse auto, clear
reg price foreign i.turn foreign#i.turn
coefplot, keep(*.foreign#*.turn)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.