Hi Stata experts,
I've been working on a graph in Stata and following the recent Stata tip I've been using by rather than graph combine.
It's certainly much easier to organise the axis labels the way I'd like so thanks Nick Cox for the tips using by graphs!
One issue I currently have probably has more to do with string manipulation rather than the graphing tool and I'd highly value any assistance!
I have a "double" by graph and would like the labels to look a bit like:

But with the Beta being the greek symbol and the 2 being subscripted.
When I make that change I get:

Notice how the beta is on the next line but the 2 = 0 on the original first line?
I've tried a few different ideas but can't quite get it to work!
In the "real" code most of the variables are programatically entered in loops etc. and the data is far more interesting, but these show what I'm trying to attempt.
Any help would be great (ideally I wanted the time values to be just given once, which I could do with the graph combine, but then the axis labels were harder to arrange!)
Cheers,
Simon.
The code below generates this random number sample for testing...
I've been working on a graph in Stata and following the recent Stata tip I've been using by rather than graph combine.
It's certainly much easier to organise the axis labels the way I'd like so thanks Nick Cox for the tips using by graphs!
One issue I currently have probably has more to do with string manipulation rather than the graphing tool and I'd highly value any assistance!
I have a "double" by graph and would like the labels to look a bit like:
But with the Beta being the greek symbol and the 2 being subscripted.
When I make that change I get:
Notice how the beta is on the next line but the 2 = 0 on the original first line?
I've tried a few different ideas but can't quite get it to work!
In the "real" code most of the variables are programatically entered in loops etc. and the data is far more interesting, but these show what I'm trying to attempt.
Any help would be great (ideally I wanted the time values to be just given once, which I could do with the graph combine, but then the axis labels were harder to arrange!)
Cheers,
Simon.
The code below generates this random number sample for testing...
Code:
//////////////////////////////////////////////////////////////////////////////// // Having difficulty getting a by graph with multiple lines in the label // along with "special" characters such as Greek letter beta and a subscript // clear things clear graph drop _all set obs 1000 // generate some random data gen id = _n gen rmse = rnormal(1,1) gen beta_2_true = mod(id,3) gen beta_3_true = mod(int((id-1)/3),3) gen aggregate_to = mod(id,5) // get the order of the daily, weekly,... label define aggregate_label 0 "daily" 1 "weekly" 2 "monthly" 3 "quarterly" 4 "yearly" label values aggregate_to aggregate_label // collapse the data ready to graph collapse (mean) graph_parameter = rmse , by(aggregate_to beta_2_true beta_3_true) ////////////// // playing with different options for trying to get the time label followed by the beta label on separate lines *gen beta_2_lab = "{&beta}" + "{sub:2}=" + string(beta_2_true) // works all on same line *gen beta_2_lab = "`=char(13)'`=char(10)'Beta2=" + string(beta_2_true) // works on separate lines without fancy symbols/subscripts gen beta_2_lab = "`=char(13)'`=char(10)'" + " {&beta}" + " {sub:2}=" + string(beta_2_true) // sub works but Beta symbol is on a separate line? *gen beta_2_lab = "`=char(13)'`=char(10)'Beta{sub:2}=" + string(beta_2_true) // sub works but Beta text is on a separate line? // combine the time and beta to a single group egen group_lab = group( aggregate_to beta_2_lab), label twoway scatter graph_parameter beta_3_true, /// xlab(0(1)2) xtitle("slope change ({&beta}{sub:3})") /// ytitle("Root Mean Square Error (RMSE)", size(small)) /// by(group_lab , row(1) note("")) /// xsize(10)
Comment