Графики с нескольких полей на одном поле marginslot в Stata

Я хотел бы нарисовать поля, полученные в результате команды margins, в одном маржинальном графике, но из разных оценок margins. Важное ограничение: эти коэффициенты находятся в пределах одного и того же минимума и максимума и поэтому сопоставимы. Как я могу это сделать?

Вот пример кода:

webuse nhanes2, clear

tnbreg psu weight hdresult iron, iterate(5) // I am using this regression type so I stick with it here

Я знаю, что могу поместить все графики отклика маржи на один график.

margins, dydx(*)
marginsplot, horizontal xline(0) yscale(reverse) recast(scatter)

Но на самом деле я запускаю три команды margins для каждого из регрессоров отдельно, потому что я хочу сравнить эффекты, если бы этот регрессор менялся. Следовательно, код

foreach var in weight hdresult iron {
  * Procedure to get the numbers for margins right
  quietly summarize `var '
  local max = r(max)
  local step = round(r(max)/6)

  quietly margins, at(`cvar'=(1(`step')`max'))
  marginsplot, title("") ytitle("")
}

Это дает мне три отдельных файла. Но я хочу, чтобы все линии были на одной фигуре, в разных цветах, конечно.

Любые предложения, как это сделать?


person MERose    schedule 24.09.2014    source источник


Ответы (2)


Используя combomarginsplot (и из файла справки):

sysuse auto, clear

oprobit rep78 i.foreign mpg price weight
margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file1, replace)

oprobit rep78 i.foreign mpg
margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file2, replace)

oprobit rep78 i.foreign mpg gear
margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file3, replace)

combomarginsplot file1 file2 file3, ///
    labels("Full model" "Restricted model" "Gear Model") noci

combomarginsplot — написанная пользователем команда Николаса Винтера. Вы можете установить его работающим

ssc install combomarginsplot
person Roberto Ferrer    schedule 24.09.2014

Основываясь на предложении @RobertoFerrer использовать combomarginsplot, я сейчас обманываю этот пакет (спасибо Николасу Винтеру):

webuse nhanes2, clear

* Run regressions
foreach var in weight hdresult iron {
  * Trick: always regress on the same variable
  gen testvar = `var'

  * Any regression where testvar enters first - the identical variable will be omitted
  tnbreg psu ///
     testvar weight hdresult iron, iterate(5)

  * Procedure to get the numbers for margins right
  quietly summarize testvar
  local max = r(max)
  local step = round(r(max)/6)

  * Margins post estimation
  quietly margins, at(testvar=(1(`step')`max')) saving(margins_`var', replace)

  * Drop testvar so that it can be reassigned within the loop
  drop testvar
}

* Combine the margins graph information
combomarginsplot margins_weight margins_hdresult margins_iron, labels("Weight" "HDrestul" "Iron")

Конечно, имеет смысл сравнивать только коэффициенты переменных, которые находятся в одном диапазоне. Это ограничение не было частью моего первоначального ответа - извините за это.

person MERose    schedule 25.09.2014