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 on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: Graph editor: Change order of subgraphs in bygraph ?


From   "Jesper Lindhardsen" <JESLIN01@geh.regionh.dk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Graph editor: Change order of subgraphs in bygraph ?
Date   Sat, 20 Aug 2011 08:56:45 +0200

Thanks again. This is really helpful. But actually I find your
"hacking"methods more appeling as I do not need the "original" syntax to
recreate the graphs (although it can be found in the .gph file).
I tried to write a .gph parse command in Stata to switch bygraphs by
changing the .gph file, which worked fine for producing the actual file,
but the binary content bit me - so the resultant file was useless :-) I
guess one could combine toyr to approaches.....

BW, Jesper



Scott wrote:

I remember reading in Kit Baum's "An Introduction to Stata
Programming" that *.gph files were actually programs to reproduce the
graph.

Looking back at section "10.5 Extracting data from graph files'
sersets" shows that there is an easier way:

//create original graph
sysuse sp500,clear
xtile g= date, n(4)
twoway bar change date , by(g,  rescale  ) xlabel(, labsize(*.7))
graph save Graph "C:\Documents and
Settings\scott.merryman\Desktop\Graph.gph",replace

//extract data from graph
cd  "C:\Documents and Settings\scott.merryman\Desktop\"
clear*
serset clear
graph use  "Graph.gph"
serset dir
serset
forv i = 0/`=r(id)' {
	serset set `i'
	serset use
	gen group = `=`i'+1'
	save temp`i'.dta,replace
	local files "`files' temp`i'.dta "
}
clear
append using  `files'
clonevar gr2 = group
replace gr2 = 4 if group == 1
replace gr2 = 1 if group==4
label define group 1 "4" 2 "2" 3 "3" 4 "1"
label value gr2 group
twoway bar change date , by(gr2,  rescale  ) ///
  xlabel(, labsize(*.7)) name(graph_new,replace)


Hope this helps,
Scott


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