Code:
// Using Mac O/S
version 17.0
sysuse auto.dta
foreach n in 0 1 {
sum mpg if for==`n'
scalar min`n' = r(min)
scalar max`n' = r(max)
}
reg price c.mpg##c.mpg##c.mpg##i.for trunk
margins, at(mpg=(`=min0' (1) `=max0') for=0) at(mpg=(`=min1' (1) `=max1') for=1)
marginsplot, recast(line) recastci(rarea) ciopt(color(%35)) ///
plot(, label("Domestic" "Foreign")) ///
plot2opts(lwidth(thick) lpattern(dash)) legend(rows(1) pos(6))Here is the output before the plot is produced:
Variables that uniquely identify margins: mpg _atopt
Multiple at() options specified:
_atoption=1: mpg=(12 (1) 34) for=0
_atoption=2: mpg=(14 (1) 41) for=1
Multiple at() options specified:
_atoption=1: mpg=(12 (1) 34) for=0
_atoption=2: mpg=(14 (1) 41) for=1
Code:
// Using Mac O/S
version 17.0
use els_mini.dta, clear
foreach n in 0 1 2 3 {
sum ses if race==`n'
scalar min`n' = r(min)
scalar max`n' = r(max)
}
reg math10 c.ses##c.ses##c.ses##i.race
margins, at(ses=(`=min0' (.1) `=max0') race=0) at(ses=(`=min3' (.1) `=max3') race=3)
marginsplot, nociFor some reason, the ‘marginsplot’ for the second example does not recognize that I have two groups to plot, which is why all of the predictions are connected together with one line (not two). In the output that Stata produces before presenting the plot, the “_atopt” is missing as a variable that uniquely identifies the margins.
Variables that uniquely identify margins: ses
Multiple at() options specified:
_atoption=1: ses=(-2.11 (.1) 1.8) race=0
_atoption=2: ses=(-1.77 (.1) 1.82) race=3
Multiple at() options specified:
_atoption=1: ses=(-2.11 (.1) 1.8) race=0
_atoption=2: ses=(-1.77 (.1) 1.82) race=3
Array
0 Response to Problem with ‘marginsplot’ when using margins command with multiple at() predictions
Post a Comment