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

RE: st: Graphing table of odds ratios generated by e.g., gologit2

From   "Nick Cox" <>
To   <>
Subject   RE: st: Graphing table of odds ratios generated by e.g., gologit2
Date   Fri, 17 Jul 2009 18:04:40 +0100

Thanks for this. Note that the code 

else {
  replace `coefficient'=. in `num'

replaces missings with missings, to no useful purpose. 

On your question, I am guessing that you want the items of `eqlist' to
end up as value labels. 

tokenize "`eqlist'" 
forval i = 1/`eqnum' { 
	local call `call' `i' "``i''" 

... xla(`call') 

would be one way to do that. 


Roy Wada

Thanks, Nick. Dropping variables will not bite since -preserve- is 
applied, but it is a poor programming style. A better way is to give 
labels to temp variables, which would have prevented them from showing 
up on the axis.
The passthru options did occur to me when I started thinking about 
the color. I twisted it so it is now available for the scatter 
graph, for the qfit graph, and for both graphs (the twoway).
The program now comes with options for saving the graph points should 
someone wants to make a graph on their own.
An interesting extension is to make a similar graph across estimates, 
sort of like a graphic version of a regression table. It should be 
useful when CI is added.
Feel free to chime in if someone has suggestions. If anyone knows 
how to pass the label values to the graph values (replace 1, 2, etc, 
with value labels on the axis), I would be interested.
sysuse auto, clear
reg3 (price mpg) (price mpg rep78) (price mpg rep78 headroom) (price mpg
rep78 headroom length)
paragr mpg, qfit(xtitle(X-Axis Title)) scatter(mcolor(blue)) title(Big
Title) eq(myeq) coef(mycoef)
*! paragr 1.0.1 16Jul2009 by
*! parallel graphing of a coefficient across different equations
prog define paragr
version 8.0
syntax varlist(min=1 max=1) [, qfit QFIT2(str asis) SCATter(str asis)
EQsave(string) COEFsave(string) *]
local var `varlist'
qui {
tempname coef coefficient equation
mat `coef'=e(b)
local eqlist : coleq `coef'
local eqlist: list clean local(eqlist)
local eqlist: list uniq local(eqlist)
local eqnum: word count `eqlist'
gen `equation'=_n
gen `coefficient'=.
forval num=1/`eqnum' {
 local name: word `num' of `eqlist'
 cap mat temp`num'=`coef'[1,"`name':`var'"]
 if _rc==0 {
  local temp`num'=temp`num'[1,1]
  replace `coefficient'=`temp`num'' in `num'
 else {
  replace `coefficient'=. in `num'
 * quantile stuff
 if "`e(cmd)'"=="qreg" | "`e(cmd)'"=="iqreg" | "`e(cmd)'"=="sqreg" |
"`e(cmd)'"=="bsqreg" {
  local tempname=subinstr("`name'","q",".",.)
  replace `equation'=`tempname' in `num'
* labels
label var `equation' "Equations"
if "`e(cmd)'"=="qreg" | "`e(cmd)'"=="iqreg" | "`e(cmd)'"=="sqreg" |
"`e(cmd)'"=="bsqreg" {
 label var `equation' "Quantiles"
local content: var label `var'
label var `coefficient' "`content'"
label define vallab 0 "no" 1 "yes"
label val `equation'  vallab
if "`qfit'"=="" & "`qfit2'"=="" {
 twoway (scatter `coefficient' `equation' in 1/`eqnum', `scatter'),
else {
 twoway (scatter `coefficient' `equation' in 1/`eqnum', `scatter') /*
 */ (qfit `coefficient' `equation' in 1/`eqnum', `qfit2' ), `options'
* save variables
if "`eqsave'"~="" {
 local N=_N
 replace `equation'=. in `=`eqnum'+1'/`N'
 gen `eqsave'=`equation'
if "`COEFsave'"~="" {
 gen `COEFsave'=`coefficient'
} /* quiet */

> 1. The program works with variables -coefficient- and -equation-,
> -drop-ping any existing instance of either variable. This is not
> necessary and often considered to be poor Stata programming style. 
> 2. The options -xlabel()- and -ylabel()- are used in non-standard
> In a Stata graphics context these always mean axis labels, not axis
> titles. (I do realise that "axis label" often means elsewhere what
> takes to be axis title, but Stata conventions are what count in
> 3. Any serious user of a graphics program will want to reach through
> tune any detail of the graph. This is at present only possible through
> the Graph Editor.
> 4. The qualifier -in 1/`eqnum'- will be faster than -if _n <=
> 5. -replace-ing missings by missings is unnecessary. 

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index