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: RE: percent symbols in catplot
From
"Martin Weiss" <[email protected]>
To
<[email protected]>
Subject
RE: st: RE: percent symbols in catplot
Date
Sat, 27 Feb 2010 00:02:54 +0100
<>
" The only way -sum- should report a missing r(max) is if all the data in
the variable were missing"
I am not sure about that. It would appear from the example that "r(max)" is
not returned at all in this case:
*******
clear*
set obs 100
gen x=.
ins x
su x
ret li
if mi(`r(max)') {
di in r "MISSING!!!"
}
else{
di in r "NOT MISSING!!!"
}
*******
HTH
Martin
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Eric Booth
Sent: Freitag, 26. Februar 2010 23:37
To: [email protected]
Subject: Re: st: RE: percent symbols in catplot
>
On Feb 26, 2010, at 4:18 PM, Martin Weiss wrote:
> BTW Eric, is there a conceivable case that would require one to check for
a
> missing "r(max)"? Anyway, the instinct to check for missings whenever
> "greater than" is employed is a healthy one :-)
No, it's just habit. The only way -sum- should report a missing r(max) is
if all the data in the variable were missing--which wouldn't lend its self
to a useful graph.
Thanks for updating this to address my second example. In applying this to
my real data, I used -graph combine- but this is faster than waiting on
-graph combine-. Also, there is an advantage in using the "by" option, in
lieu of -graph combine-, in that it leaves out the extra set of yaxis
labels, which looks much nicer, and it places the "by" group labels at the
top of the graphs automatically.
Best,
Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Feb 26, 2010, at 4:18 PM, Martin Weiss wrote:
>
> <>
>
> The second graph requested in Eric`s initial post requires some
> modification:
>
>
> *******
> sysuse auto, clear
> contract rep78 foreign, percent(perc)
> *-----added
> qui sum perc
> local x = round(`r(min)', 10)
> local y = round(`r(max)', 10)+10
> local t 10
> if `r(max)'>75 & !mi(`r(max)') {
> local t 25
> }
> mylabels `x'(`t')`y', local(labels) myscale(@) suffix("%")
> *------
> gen strpercent=string(perc, "%4.1fc")+ " %" /*chg. to 1 dec place*/
> twoway (bar perc rep78) /*
> */ (scatter perc rep78, mlabcolor(black) msymbol(none) /*
> */ mlabsize(medium) mlabel(strpercent) /*
> */ mlabposition(12)), by(foreign, legend(off) note("")) /*
> */ yla(`labels') // <-- changed to use local created by -mylabels-
> *******
>
> BTW Eric, is there a conceivable case that would require one to check for
a
> missing "r(max)"? Anyway, the instinct to check for missings whenever
> "greater than" is employed is a healthy one :-)
>
>
> HTH
> Martin
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Eric Booth
> Sent: Freitag, 26. Februar 2010 22:33
> To: [email protected]
> Subject: Re: st: RE: percent symbols in catplot
>
>>
>
> Thanks, Martin.
> This is a great workaround for my situation (& it's much better than my
idea
> of tinkering with the .grec file output).
>
>
>> I failed to bring this up at the last wishes & grumbles in Florence. A
>> -format- that adds the percentage sign, just like in spreadsheet
> software...
>
> Yes I agree, hopefully Stata will implement a percentage format someday.
>
> ___
> Just FYI for anyone else who needs something like this:
> I slightly modified Martin's example to use NJC's -mylabels- (from SSC &
> referenced in the 2008 thread Martin referred me to) so that I could
easily
> shift the yaxis with the range of the data in a way that makes sense for
the
> way I need to display results--so, something like:
>
> *******begin
> sysuse auto, clear
> contract rep78, percent(perc)
> *-----added
> qui sum perc
> local x = round(`r(min)', 10)
> local y = round(`r(max)', 10)+10
> local t 10
> if `r(max)'>75 & !mi(`r(max)') {
> local t 25
> }
> mylabels `x'(`t')`y', local(labels) myscale(@) suffix("%")
> *------
> gen strpercent=string(perc, "%4.1fc")+ " %" /*chg. to 1 dec place*/
> twoway (bar perc rep78) /*
> */ (scatter perc rep78, mlabcolor(black) msymbol(none) /*
> */ mlabsize(medium) mlabel(strpercent) /*
> */ mlabposition(12)), legend(off) /*
> */ yla(`labels') // <-- changed to use local created by -mylabels-
> *******end
> (note that the ylab changes from increasing by 10 to increasing by 25 if
the
> r(max) > 75)
>
>
> Thanks again,
>
> Eric
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
> Office: +979.845.6754
>
>
> On Feb 26, 2010, at 2:47 PM, Martin Weiss wrote:
>
>>
>> <>
>>
>> You can always go for a kludge:
>>
>>
>> *******
>> sysuse auto, clear
>> contract rep78, percent(perc)
>> gen strpercent=string(perc, "%4.2fc")+ " %"
>> twoway (bar perc rep78) /*
>> */ (scatter perc rep78, mlabcolor(black) msymbol(none) /*
>> */ mlabsize(medium) mlabel(strpercent) /*
>> */ mlabposition(12)), legend(off) /*
>> */ yla(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%")
>> *******
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Eric Booth
>> Sent: Freitag, 26. Februar 2010 21:12
>> To: [email protected]
>> Subject: st: percent symbols in catplot
>>
>>>
>>
>> I am using -catplot- (from SSC) on Stata 11 MP for Mac OSX. I'd like to
>> show the percent sign in the label for each of the category bars when
> using
>> the "percent" option.
>>
>> For example,
>> ****
>> webuse auto, clear
>> catplot bar rep78, percent blabel(bar, position(outside) format(%9.1f))
>> **or**
>> catplot bar rep78, by( for) percent blabel(bar, position(outside)
>> format(%9.1f))
>> ****
>> shows the percent of each rep78 category out of 100, but I can't get it
to
>> show the % sign, so it could say "43.5%", etc.
>>
>> Using graph editor, I found that I can add a % sign to the bar label text
>> manually (though I'd rather not have to do that for many graphs), but
> after
>> looking through the barlabel options help documentation, I couldn't
figure
>> out how to change the bar label automatically. (I had the idea that if I
>> could override the bar labels like you can the text for a key in a legend
>> then I could calculate and substitute these values into the -catplot-
>> command in a loop, but I haven't found a way to do this using the
barlabel
>> option)
>>
>> Another option might be to write something that automates those graph
>> recorder grec file changes (ex: when I add the "%" by hand, it issues
the
>> command:
>>
>> .plotregion1.barlabels[3].text.Arrpush 43.5%
>>
>> in the recording), but this is a pain. Any suggestions?
>>
>> Thanks,
>>
>> Eric
>> __
>> Eric A. Booth
>> Public Policy Research Institute
>> Texas A&M University
>> [email protected]
>> Office: +979.845.6754
>>
>> *
*
* 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/
*
* 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/