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]
Re: st: Useful labelling of dummy variables following logit
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Useful labelling of dummy variables following logit
Date
Wed, 24 Aug 2011 18:42:35 +0200
On Wed, Aug 24, 2011 at 5:41 PM, Tim Evans <[email protected]> wrote:
> Thanks for this, it nearly works for me - I can graph it, but I don't get all of the variable values from the 'axis' column to appear - I only have random ones. Do you know why it does not display all of the variables names (but does display the estimate value)
if you have say 7 estimates than your -ylab()- option should be
-ylab(1/7, valuelabel ang(h) noticks ) to ensure that there is a label
for each estimate. The dropping is not random, Stata tries to find
nice values for labels, so it can easily happen that it only displays
an axis label for every 2nd or 5th parameter. For most graphs makes
perfect sense, just not for ours, so need to explicitly tell Stata to
which values it needs to attach a label.
The added problem here is that Tim is interested in factor variables.
In that case you would not want the variable label but the value
label. I have modified the example further to ensure that happens.
*------------------------ begin example -------------------------
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("")
*--------------------- end example -----------------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/