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]

st: Combining a regression table with graph in Stata


From   Tim Evans <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Combining a regression table with graph in Stata
Date   Mon, 3 Feb 2014 13:43:18 +0000

Hi all,

I'm using Stata 11.2 (although if it's easier for the solution can use Stata 13) and have run a logistic regression model and saved the results using -parmest- (available from SSC) into a stata .dta file. From here I can export the results into a table (MS Excel or other) or I can graph in Stata (which I do). However, I'm pushed for space in the publication so would like to know if there is a way in Stata to combine the estimates from the table along with the graphical representation (similar to this table/graph combination: 

http://www.spandidos-publications.com/article_images/br/1/4/BR-01-04-0629-g02.jpg)

This is some example code that will produce the estimates in a stata file followed by the graph:

sysuse nlsw88, clear

replace ttl_exp = ttl_exp / 10 // experience in decades
replace grade = grade - 12 // center education at meaningful value
logit union i.race i.south grade ttl_exp, or

foreach v in grade ttl_ex { // continuous variables
       local l`v' : variable label `v'
	   if `"`l`v''"' == "" { // if no variable label
			local l`v' "`v'"
	   }
}
foreach v in south race { // factor variables
	levelsof `v'
	local `v'levs `r(levels)'
	foreach l in ``v'levs' {
		local l`v'_`l' : label (`v') `l'
		if `"`l`v'_`l''"' == "`l'" { // if no value label
			local l`v'_`l' `"`v' == `l'"'
		}
	}
}

parmest, norestore eform
foreach v in grade ttl_ex {
   replace parm = "`l`v''" if parm == "`v'"
}
foreach v in south race {
	local i = 1
	foreach l in ``v'levs' {
		if `i' == 1 {
			drop if parm == "`l'b.`v'" // drop reference
		}
		else {
			replace parm = "`l`v'_`l''" if parm == "`l'.`v'"
		}
		local i = `i' + 1
	}
}
replace parm = "baseline odds" if parm == "_cons"
egen axis= axis(z), label(parm)
twoway bar  estimate axis, base(1) horizontal barw(.5) ///
           xline(1) ylab(1/6, valuelabel ang(h) noticks) ||             ///
      rcap min95 max95 axis, horizontal               ///
           legend(order(1 "point estimate"            ///
                        2 "95% conf. int.") pos(6))   ///
           xtitle("odds ratio") ytitle("")

Best wishes

Tim

**************************************************************************
The information contained in the EMail and any attachments is confidential and intended solely and for the attention and use of the named addressee(s). It may not be disclosed to any other person without the express authority of Public Health England, or the intended recipient, or both. If you are not the intended recipient, you must not disclose, copy, distribute or retain this message or any part of it. This footnote also confirms that this EMail has been swept for computer viruses by Symantec.Cloud, but please re-sweep any attachments before opening or saving. http://www.gov.uk/PHE
**************************************************************************

*
*   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