Hi everyone,
Cutting to the chase, while producing graphs, specifically catplot, I'm using splitvallabels to split my labels of the variables but while using splitvallables in catplot,
(a) one of my labels of the variable which is "other" is missing.
(b) and the distribution of the labels within the variable is also wrong.
To show you in detail, this is the code I'm trying to run:
foreach var of varlist var1 var2 var3{
cap confirm numeric var `var'
if !_rc {
local varlab : variable label `var'
local varlab = subinstr("`macval(varlab)'","$","",.)
qui sum `var'
count if !missing(`var')
local N `r(N)'
{
splitvallabels `var'
local relabel `r(relabel)'
catplot `var', percent var1opts(label(labsize(vsmall)) relabel(`r(relabel)')) blabel(bar, position(outside) format(%4.1f) size(vsmall)) ///
title("`macval(varlab)'", size(small) pos(11) justification(left)) legend(size(tiny)) l1title("") ///
ytitle ("Percentage", size(small)) graphregion(fcolor(white)) aspect(1.2) ///
note("{it:n=`N' respondents}", size(small))
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
else {
graph twoway scatteri 1 1 "No observations yet", mlabpos(0) msym(i) ///
title("`var'", pos(11) justification(left) size(small)) graphregion(fcolor(white)) ///
yscale(off noline) xscale(off noline)
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
}
}
and, this is the graph I'm getting :

While on the other hand, if I'm using the catplot without splitvallabels then all of my labels are appearing including the label "other" with the correct distribution, just the label is being cut short.
foreach var of varlist var1 var2 var3{
cap confirm numeric var `var'
if !_rc {
local varlab : variable label `var'
local varlab = subinstr("`macval(varlab)'","$","",.)
qui sum `var'
count if !missing(`var')
local N `r(N)'
{
catplot `var', percent var1opts(label(labsize(vsmall))) blabel(bar, position(outside) format(%4.1f) size(vsmall)) ///
title("`macval(varlab)'", size(small) pos(11) justification(left)) legend(size(third_tiny)) l1title("") ///
ytitle ("Percentage", size(small)) graphregion(fcolor(white)) aspect(1.2) ///
note("{it:n=`N' respondents}", size(small))
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
else {
graph twoway scatteri 1 1 "No observations yet", mlabpos(0) msym(i) ///
title("`var'", pos(11) justification(left) size(small)) graphregion(fcolor(white)) ///
yscale(off noline) xscale(off noline)
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
}
}
The graph is as follows:

Can anyone please help me why with splitvallabels, the label other is disappearing and the distribution is also happening wrong?
Thank you!
Cutting to the chase, while producing graphs, specifically catplot, I'm using splitvallabels to split my labels of the variables but while using splitvallables in catplot,
(a) one of my labels of the variable which is "other" is missing.
(b) and the distribution of the labels within the variable is also wrong.
To show you in detail, this is the code I'm trying to run:
foreach var of varlist var1 var2 var3{
cap confirm numeric var `var'
if !_rc {
local varlab : variable label `var'
local varlab = subinstr("`macval(varlab)'","$","",.)
qui sum `var'
count if !missing(`var')
local N `r(N)'
{
splitvallabels `var'
local relabel `r(relabel)'
catplot `var', percent var1opts(label(labsize(vsmall)) relabel(`r(relabel)')) blabel(bar, position(outside) format(%4.1f) size(vsmall)) ///
title("`macval(varlab)'", size(small) pos(11) justification(left)) legend(size(tiny)) l1title("") ///
ytitle ("Percentage", size(small)) graphregion(fcolor(white)) aspect(1.2) ///
note("{it:n=`N' respondents}", size(small))
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
else {
graph twoway scatteri 1 1 "No observations yet", mlabpos(0) msym(i) ///
title("`var'", pos(11) justification(left) size(small)) graphregion(fcolor(white)) ///
yscale(off noline) xscale(off noline)
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
}
}
and, this is the graph I'm getting :
While on the other hand, if I'm using the catplot without splitvallabels then all of my labels are appearing including the label "other" with the correct distribution, just the label is being cut short.
foreach var of varlist var1 var2 var3{
cap confirm numeric var `var'
if !_rc {
local varlab : variable label `var'
local varlab = subinstr("`macval(varlab)'","$","",.)
qui sum `var'
count if !missing(`var')
local N `r(N)'
{
catplot `var', percent var1opts(label(labsize(vsmall))) blabel(bar, position(outside) format(%4.1f) size(vsmall)) ///
title("`macval(varlab)'", size(small) pos(11) justification(left)) legend(size(third_tiny)) l1title("") ///
ytitle ("Percentage", size(small)) graphregion(fcolor(white)) aspect(1.2) ///
note("{it:n=`N' respondents}", size(small))
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
else {
graph twoway scatteri 1 1 "No observations yet", mlabpos(0) msym(i) ///
title("`var'", pos(11) justification(left) size(small)) graphregion(fcolor(white)) ///
yscale(off noline) xscale(off noline)
graph export "$figures/`var'.png", replace
graph export "$reports/`var'.eps", replace
}
}
}
The graph is as follows:
Can anyone please help me why with splitvallabels, the label other is disappearing and the distribution is also happening wrong?
Thank you!
Comment