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: RE: Plot estimates and ci from two regressions in one graph


From   Nikolaos Kanellopoulos <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: RE: Plot estimates and ci from two regressions in one graph
Date   Thu, 21 Jun 2012 09:06:58 +0100 (BST)

Tirthankar thank you very much for the suggestion to use marginsplot (it never crossed my mind).

Since I had something more specific in my mind I tried to utilize the flexibility of Stata and its tw command and I think I found a solution to my problem.
If anybody has anything to add in order to improve the following code is more than welcome.

Nikos


*-----------------------------------------------------------------------------------------------------------------

sysuse auto, clear
levelsof for, local(a)
tempfile file

foreach i of local a {     
    sysuse auto, clear
    count if for==`i' 

        if r(N)>=1 {
            regress mpg c.(rep78 headroom trunk weight) if for==`i' 
            parmest, norestore 
            egen axis= axis(estimate), label(parm)
            gen for=`i'
            capture append using `file'
            save `file', replace
            local kk=`i1'+1
}
}  

gsort axis -for
gen order=_N-_n

label define jj    1 "_cons"    3 "rep78" 5 "headroom"    ///
                7 "weight" 9 "trunk" 
label value order  jj 

twoway ///
(scatter order est if for==1, msymbol(circle))            ///
(scatter order est if for==0, msymbol(T))               ///
(rcap min95 max95 order, horizontal ),                  ///
ylabel(1(2)9, valuelabel angle(0)) ytitle("")            ///
legend(order (1 2) label(1 "for==1") label(2 "for==0"))    ///
xtitle("Coefficients and confidence interval")
*-----------------------------------------------------------------------------------------------------------------


----- Original Message -----
From: Tirthankar Chakravarty <[email protected]>
To: [email protected]
Cc: 
Sent: Monday, 18 June 2012, 16:19
Subject: Re: st: RE: Plot estimates and ci from two regressions in one graph

-marginsplot- is very powerful for these kinds of problems.

*------------------------------------------------------------------------
sysuse auto, clear
reg mpg i.foreign##c.(rep78 headroom trunk weight)
margins, dydx(*) over(foreign)
marginsplot, xdim(_deriv)
*------------------------------------------------------------------------

Note however that without standardizing the variables, you might not
be able to make out the variations in coefficients across  groups.

T



On Mon, Jun 18, 2012 at 5:36 AM, Nikolaos Kanellopoulos
<[email protected]> wrote:
> Dear Nick,
>
> thanks for the quick reply.
>
> Unfortunatelly I don't want to plot the predicted probability but the point estimate of x (which in my case is more than one) and it's confidence interval.
> Thank you anyway.
>
> Nikos
>
> ----- Original Message -----
> From: Nick Cox <[email protected]>
> To: "[email protected]" <[email protected]>
> Cc:
> Sent: Monday, 18 June 2012, 15:27
> Subject: st: RE: Plot estimates and ci from two regressions in one graph
>
> This doesn't seem to require any user-written stuff.
>
> twoway lfitci <whatever> || lfitci <whatever>
>
> Nick
> [email protected]
>
> Nikolaos Kanellopoulos
>
> I want to plot the estimates and their confidence intervals from two regressions.
> This sounds like a job for eclplot (downloaded from ssc).  The code in the end of the email shows how this can be done but the graphs for each regression appear next to each other.
> I want to have this in one single graph. I want the estimates from the first regression to appear over those from the second regression.
>
> Is it possible to do something like this in Stata?
>
> Thank you in advance
> Nikos
>
> sysuse auto,clear
>
> tempfile tf1 tf2
> parmby "reg mpg rep78 headroom trunk weight if foreign==0", lab saving(ʽtf1ʼ,replace) idn(1) ids(NoFor)
> parmby "reg mpg rep78 headroom trunk weight if foreign==1", lab saving(ʽtf2ʼ,replace) idn(2) ids(For)
> dsconcat ʽtf1ʼ ʽtf2ʼ
> sencode idstr, gene(modtype)
> sencode label, gene(predictor)
> lab var modtype "Type of model"
> lab var predictor "Predictor"
> sort modtype predictor
> eclplot estimate min95 max95 predictor, hori by(modtype,legend(off) compact)
>
>
> *
> *  For searches and help try:
> *  http://www.stata.com/help.cgi?search
> *  http://www.stata.com/support/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/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/



-- 
Tirthankar Chakravarty
[email protected]
[email protected]

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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