Размещать только термины взаимодействия в коэфплоте
После регрессии в Stata я пытаюсь построить только коэффициенты членов взаимодействия.
Мне не удалось сделать это с помощью команды сообщества coefplot
,
Вот воспроизводимый пример и мои попытки решения:
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 )
Есть ли другой способ это сделать?
Я написал этот вопрос на сайте Statalist.
2 ответа
Решение
Вам просто нужно указать взаимодействия:
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')
РЕДАКТИРОВАТЬ:
Вы также можете получить все ненулевые коэффициенты следующим образом:
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')
Решение немного проще, чем уже предложенное, - использовать символы подстановки («*» или «?»).
sysuse auto, clear
reg price foreign i.turn foreign#i.turn
coefplot, keep(*.foreign#*.turn)