Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Merging two plots in one coordination


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: Merging two plots in one coordination
Date   Wed, 8 Jan 2014 14:09:04 -0600

-margins- has the option -post- from which you could extract the
marginal values and confidence intervals.

Another way is to extract the data from the serset used to graph the
marginsplots:


tempfile tmp
clear
set obs 100
gen double x1 = rnormal()
gen double x2 = floor((5-1+1)*runiform() + 1)
gen xb1 = -1 + 1*x1 + .5*x2
gen xb2 = -3 + 2*x1 + x2
gen y1 = rpoisson(exp(xb1))
gen y2 = rpoisson(exp(xb2))

poisson y1 x1 x2
margins, at(x2 = (1(1)5)) atmeans
marginsplot

preserve
serset use,clear
rename (_margin _ci_lb _ci_ub __0) (margin1 lb1 ub1 x2)
save `tmp'
restore

poisson y2 x1 x2
margins, at(x2 = (1(1)5)) atmeans
marginsplot

serset use,clear
rename (_margin _ci_lb _ci_ub  __0 ) (margin2 lb2 ub2 x2)
merge 1:1 x2 using `tmp'

twoway rcap ub1 lb1 x2  , lc(blue) ///
 || connect margin1 x2, lc(blue) mc(blue)  ///
 || rcap ub2 lb2 x2, lc(black) ///
 || connect margin2 x2 , lc(black) mc(black) ///
 ||, legend(order(2 "Y1" 4 "Y2"))


Scott



On Wed, Jan 8, 2014 at 8:03 AM, James Bernard <[email protected]> wrote:
> Hi all,
>
> I am using -margins and -marginsplot to plot predicted values of a
> Poisson regression. I run two models and I want to see both fitted
> curves in one one graph.
>
> I thought of using -addplot. But, it does not work with -marginsplot
>
> What should I do?
>
> Many Thanks,
> James
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index