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   Roy Wada <[email protected]>
To   <[email protected]>
Subject   RE: st: Graphing table of odds ratios generated by e.g., gologit2
Date   Thu, 16 Jul 2009 18:45:24 -0700

> 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 [email protected]
*! 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
 
 
_________________________________________________________________
Insert movie times and more without leaving Hotmail®. 
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index