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
[email protected]
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 [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
*
* 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/