Bookmark and Share

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: Changing titles of graphs in a loop without doing all the graphs again


From   Benjamin Villena Roldan <[email protected]>
To   [email protected]
Subject   Re: st: Changing titles of graphs in a loop without doing all the graphs again
Date   Sun, 16 Mar 2014 01:21:50 -0300 (ART)

Dear statalist,
Since I got no reply to my query, I am trying something to change the titles of these time-consuming graphs. There might be an alternative approach to what I will explain here. I'm interested in any solution that actually works.

This is what I have done: I realized that the Graph Editor recorded tasks define a grec file that is editable. The challenge is to pass a generic title and title axes so that the graph changes by executing the grec file through -graph play-. I figured out that local macros do not work. A global macro does the trick.

My grec file "change_titles" looks like this

StataFileTM:00001:01100:GREC:                          :
00003:00003:00001:
*! classname: twowaygraph_g
*! family: twoway
*! date: 15 Mar 2014
*! time: 22:25:31
*! graph_scheme: s2mono
*! naturallywhite: 1
*! end

// File created by Graph Editor Recorder.
// Edit only if you know what you are doing.

.xaxis1.title.text = {}
.xaxis1.title.text.Arrpush $newxaxis
// title edits

.yaxis1.title.text = {}
.yaxis1.title.text.Arrpush $newyaxis
// title edits

.title.text = {}
.title.text.Arrpush $newtitle
// title edits


// <end>

Then, I write the code you will find below to change graphs and combine six of them into an array of graphs.

_____________________________________________________

graph drop _all
local YS aprobns wordns pcomns 
local YSN APROB WORD PCOM
local T S
local u a
global newyaxis "Avg Marg Response (SD)"
local n : word count `YS'
foreach lab in cage momedu {
	local grlist
	if "`lab'"=="cage" global newxaxis "Age Child"
	if "`lab'"=="momedu" global newxaxis "Years Mom Education"
. 	forv j = 1/`n' {
		local y : word `j' of `YS'
		local yn : word `j' of `YSN'
		graph use d`y'dL5`y'_`lab'_`T'`u'
		*Define grec file first
		global newtitle "`yn'(t-5) => `yn'(t)"
		graph play change_titles
		graph rename d`y'dL5`y'_`lab'_`T'`u' Nd`y'dL5`y'_`lab'_`T'`u'
		graph save Nd`y'dL5`y'_`lab'_`T'`u', replace
		graph drop _all
	}	
}


*Combine in separate stage
graph drop _all
foreach lab in cage momedu {
. 	forv j = 1/`n' {
		local y : word `j' of `YS'
		graph use Nd`y'dL5`y'_`lab'_`T'`u'
		local grlist `grlist' Nd`y'dL5`y'_`lab'_`T'`u'
	}	
	graph combine `grlist', `options' name(SP`lab', replace) ycom xcom rows(1) cols(3)
}

graph combine SPcage SPmomedu , `options' name(SP_cage_momedu_`T'`u', replace) rows(2) cols(1)

___________________________________________________


The strange behavior I observe is that any time I combine the graphs, all the titles I assigned through a global macro are changed to the last value of the global macro, in all the graphs. It seems that the global is somehow embedded in the graph, and every time I change the content of the global macro, it changes in all graphs. This behavior remains even if I rename graphs, save them under a new name, and I perform the combine stage in a separate loop. I even put a -clear all- between the two loops to make sure globals somehow do not go into graphs again. Nothing seems to work here.

I may have taken an overall wrong approach here. What I am doing seemed reasonable, but I do not know why it does not work. Of course, I could produce all the graphs again from scratch, but it would take me several days. Another option is changing all graphs individually, but I am trying to make it in a more automatized way to prevent mistakes.

I hope you can help me here

All the best

B.



----- Original Message -----
From: "Benjamin Villena Roldan" <[email protected]>
To: [email protected]
Sent: Saturday, March 15, 2014 6:49:16 PM
Subject: st: Changing titles of graphs in a loop without doing all the graphs again



Dear statalist

I have various dozens of graphs I computed using margins from a complicated model. 
My problem is I need to change their titles now.
Since it took several days to compute all of them, I am wondering if there is a way I could edit just the titles of these graphs without running the whole thing again. Of course, the cumbersome way to do it is just using the graph editor, but it will be too time-consuming. 

I hope you can help me

Best

B.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index