Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Changing title with by option ?


From   "Heekyung Hellen Kim" <hekim@mit.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Changing title with by option ?
Date   Thu, 15 Jul 2010 12:09:47 -0400

Wow.. Thank you!!  

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eric Booth
Sent: Thursday, July 15, 2010 11:49 AM
To: <statalist@hsphsun2.harvard.edu>
Subject: Re: st: Changing title with by option ?

<>

While creating my previous example, I was trying to use the macro extended
function "piece" to break up the value label automatically (rather than
having to define each title in a macro manually).  This would be
increasingly useful if you had a lot more "by" categories & therefore a lot
more graphs & title macros to create.    I kept getting a syntax error with
the extended function, but I got it worked out after I posted.  
Here's my previous example reworked using the macro extended function:

******************!
clear
**SETUP:     create vars  and label vars**
set obs 1000
g x = abs(runiform()*100)
g y = abs(runiform()*10)
g category = 1+int((3-1+1)*runiform())
	lab var x "Quantity of X"
	lab var y "Quantity of Y"
**label values**
//I added spaces using find/replace to allow the extended function below to
find pieces**
lab def ll 1 "Mining / Quarrying / Oil&Gas / Extraction / Utilities /
Construction / Manufacturing" , modify
lab def ll 2 "Extraction / Mining / Construction / Manufacturing / Quarrying
/ Oil&Gas / Utilities" , modify
lab def ll 3 "Oil&Gas / Utilities / Extraction / Mining / Construction /
Manufacturing / OTHER", modify
label val cat ll

*************
*************

qui su categ
forval n = `r(min)'/`r(max)' {

***********new**************
**create titles by breaking up the value labels into 3 parts**
local title`n'a: piece 1 24 of "`:lab ll  `n''", nobreak
local title`n'b: piece 2 24 of "`:lab ll  `n''", nobreak
local title`n'c: piece 3 24 of "`:lab ll  `n''", nobreak
local title`n' ""`title`n'a'"  "`title`n'b'" "`title`n'c'""
di `"`title`n''"'
***********new**************

	scatter y x if category==`n',    ///
   		title(`title`n'', size(medsmall)) name(graph`n', replace) 
   graph save graph`n' "graph`n'.gph", replace
     }
   graph combine graph1 graph2 graph3, ///
   rows(1) title("{stSerif:OVERALL TITLE GOES HERE}")  note("{bf:Source:}
Data source is X") 

******************!

~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754



On Jul 15, 2010, at 9:43 AM, Eric Booth wrote:

> <>
> 
> Hi  
> 
> You can avoid using the graph editor by treating each "by" category as an
"if" condition for a separate graph and then using -graph combine- to put
them together:
> 
> ******************!
> clear
> **SETUP:     create vars  and label vars**
> set obs 100
> g x = abs(runiform()*100)
> g y = abs(runiform()*10)
> g category = 1+int((3-1+1)*runiform())
> 	lab var x "Quantity of X"
> 	lab var y "Quantity of Y"
> 
> 
> **label values**
> lab def ll 1
"Mining/Quarrying/Oil&Gas/Extraction/Utilities/Construction/Manufacturing" ,
modify
> lab def ll 2
"Extraction/Mining/Construction/Manufacturing/Quarrying/Oil&Gas/Utilities" ,
modify
> lab def ll 3
"Oil&Gas/Utilities/Extraction/Mining/Construction/Manufacturing/OTHER",
modify
> lab val category ll
> la li
> 
> **graph titles**
> local title1 ""{bf:Mining/Quarrying/Oil&Gas}" "Extraction/Utilities"
"{it:Construction/Manufacturing}"" 
> local title2 ""{bf:Extraction/Mining/Construction}"
"Manufacturing/Quarrying" "{it:Oil&Gas/Utilities}"" 
> local title3 ""{bf:Oil&Gas/Utilities/Extraction}" "Mining/Construction"
"{it:Manufacturing/OTHER}""
> 
> *************
> *************
> 
> 
> //EXAMPLE 1//
> ****create graphs & combine****
> qui su categ
> forval n = `r(min)'/`r(max)' {
> 	scatter y x if category==`n',    ///
>    title(`title`n'', size(medsmall)) name(graph`n', replace) 
>    graph save graph`n' "graph`n'.gph", replace
>      }
>    graph combine graph1 graph2 graph3, ///
>    rows(1) title("{stSerif:OVERALL TITLE GOES HERE}")  note("{bf:Source:}
Data source is X") 
> 
> 
> 
> //EXAMPLE 2//
> **Put this info in a text box or note and use shorter titles:
> 
> qui su categ
> forval n = `r(min)'/`r(max)' {
> 	scatter y x if category==`n',    ///
> title({stSerif:Industrial Activities for {bf:Nation `n'}}, size(medsmall))
name(graph`n', replace)  ///
> text(1 85 `title`n'', orient(horizontal) si(vsmall) justification(center)
box ) 
>    graph save graph`n' "graph`n'.gph", replace
>      }
>    graph combine graph1 graph2 graph3, ///
>    rows(1) title("{bf:{stSerif:OVERALL TITLE GOES HERE}}")
note("{bf:Source:}  Data source is X") 
> ******************!
> 
> I prefer to have less information than is in your value labels as the
title of a graph.  I think the information in your value labels is better
used in a note, text box, etc; so,  I would probably go with something
closer to EXAMPLE 2 above.
> 
> ~ Eric
> 
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> ebooth@ppri.tamu.edu
> Office: +979.845.6754
> 
> 
> 
> On Jul 15, 2010, at 5:35 AM, Maarten buis wrote:
> 
>> --------------------------
>> Maarten L. Buis
>> Institut fuer Soziologie
>> Universitaet Tuebingen
>> Wilhelmstrasse 36
>> 72074 Tuebingen
>> Germany
>> 
>> http://www.maartenbuis.nl
>> --------------------------
>> 
>> 
>> --- On Thu, 15/7/10, Heekyung Hellen Kim wrote:
>>>> My label for category is too long to put in one
>>>> line over each graph.  Is there any way to appear
>>>> in two lines?
>>>> 
>>>> For example, 
>>>> 
>>>> Category 1 = Mining/Quarrying/Oil&Gas
>>>> Extraction/Utilities/Construction/Manufacturing
>> 
>> --- On Thu, 15/7/10, Maarten buis wrote:
>>> Yes, but for titles above each by-graph you will 
>>> need to use the graph editor:
>>> 
>>> 1. Create your graph with the long titles
>>> 2. Open the graph editor, within the graph window
>>>   go to File, and than to Start Graph Editor.
>>> 3. click on the title you want to change
>>> 4. enclose each part that you want to appear on a
>>>   single line in double quotes. So in your case:
>>> "Mining/Quarrying/Oil&Gas" "Extraction/Utilities/
>>> Construction/Manufacturing"
>> 
>> I've shown this recommendation in the movie below:
>>
<http://www.screencast.com/users/maartenbuis/folders/Jing/media/3b2dfbc4-25c
8-49e8-b19e-8f9d8120a738>
>> 
>> Hope this helps,
>> Maarten
>> 
>> 



*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index