Statalist


[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   John LeBlanc <leblancj@dal.ca>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Graphing table of odds ratios generated by e.g., gologit2
Date   Fri, 17 Jul 2009 11:12:48 -0300

Thank you Nick & Roy! I will work through these and let Statalist know of my results.

John LeBlanc

Nick Cox wrote:
This program will no doubt be very useful. I have further suggestions:
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 ways.
In a Stata graphics context these always mean axis labels, not axis
titles. (I do realise that "axis label" often means elsewhere what Stata
takes to be axis title, but Stata conventions are what count in Stata.)
3. Any serious user of a graphics program will want to reach through and
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 <= `eqnum'-. 5. -replace-ing missings by missings is unnecessary.
Below is a version that incorporates all these suggestions. The wildcard
* means that any options of -twoway scatter- can be passed to tune the
linear plot. -xlabel()- and -ylabel()- are removed as explicit options,
as -xtitle()- and -ytitle()- are now available for the same purpose. In
addition to -qfit- there is now a -qfit()- option which can be used to
carry options for that superimposed graph. This is untested code.
* touched NJC 17 July 2009
prog define paragr2
version 8.0
syntax varlist(min=1 max=1) [, qfit QFIT2(str asis) *]
local var `varlist'
qui {
preserve
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'
 }

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

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'"

if "`qfit'" == "" & `"`qfit2'"' == "" {
scatter `coefficient' `equation' in 1/`eqnum', `options' }
else {
 twoway (scatter `coefficient' `equation' in 1/`eqnum', `options') (qfit
`coefficient' `equation' in 1/`eqnum', `qfit2')
}
} /* quit */
end

Nick n.j.cox@durham.ac.uk
Roy Wada

Gologit2 with the gamma option generates tables of coefficients or
odds
ratios with predictor vars on one axis and values of the ordinal
dependent var on the other. I suspect that one could save these to a
matrix and then generate a graph where each line represents the odds
ratio for a predictor variable for each value of the dependent
variable.
This would be a nice way to assess proportional odds assumption.

Regards, John LeBlanc

For -gologit2- from ssc, gamma is actually the difference acrss the coefficients. It's probably more straightforward to plot the coefficients themselves. Here is a program that will do a parallel graphing of a coefficient across equations. It shows one way to extract matrix content. Should be up on ssc whenever Kit gets to it.

* reg3
sysuse auto, clear
reg3 (price mpg) (price mpg rep78) (price mpg rep78 headroom) (price mpg
rep78 headroom length)
paragr mpg, xlabel(Equation)

* sqreg
sysuse auto, clear
sqreg price mpg rep78 headroom length, q(.10 .25 .50 .75 .90) reps(25)
paragr mpg, qfit

* Unconstrained model with gologit
sysuse auto, clear
egen money=cut(price), group(8)
gologit money headroom mpg weight length turn displacemen
paragr displacement

* constrained model with gologit2 from ssc (need Stata 8.2 or better)
sysuse auto, clear
egen money=cut(price), group(5)
gologit2 money headroom mpg weight length turn displacement, auto
paragr weight, qfit ylabel(odds ratios) xlabel(cut)

*! paragr 1.0.0 16Jul2009 by roywada@hotmail.com
*! parallel graphing of the same coefficient across different equations
prog define paragr
version 8.0
syntax varlist(min=1 max=1) [, qfit Xlabel(string) Ylabel(string)]
local var `varlist'
qui {
preserve
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'
 }
}
cap drop equation
cap drop coefficient
gen equation=`equation'
if "`e(cmd)'"=="qreg" | "`e(cmd)'"=="iqreg" | "`e(cmd)'"=="sqreg" |
"`e(cmd)'"=="bsqreg" {
 label var equation "Quantiles"
}
if "`xlabel'"~="" {
 label var equation "`xlabel'"
}
gen coefficient=`coefficient'
local content: var label `var'
label var coefficient "`content'"
if "`ylabel'"~="" {
 label var coefficient "`ylabel'"
}
if "`qfit'"~="qfit" {
 scatter coefficient equation if _n<=`eqnum'
}
else {
 twoway (scatter coefficient equation if _n<=`eqnum') (qfit coefficient
equation if _n<=`eqnum')
}
} /* quit */
end
exit

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


--

Regards, John LeBlanc

_________________________________________________________



John C. LeBlanc, MD, MSc, FRCPC
Associate Professor

Pediatrics, Psychiatry, Community Health and Epidemiology

Dalhousie University



IWK Health Centre              Work phone: (902) 470-8930

5850 University Avenue         Work fax:   (902) 470-6913

Halifax, Nova Scotia           Email: John.LeBlanc@Dal.Ca

B3K 6R8 CANADA                 Pager: (902) 470-8888

________________________________________________________________



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index