I have a code where I divide a country in regions. So, the I create a variable like.
But then, in order to facilatate, I create labels, just like:
But now I want to generate some graphs using the structure foreach (below), where I want to gen a graph for each region. But inside the title, I would like that appear the name/label of the region ("sudeste", "sul", "exterior") and not the numbers (1,2,3).
I know this structure above works fine for strings. It also work here in fact, but the variable is indeed numbers, so I can't use it also in graph title.
Well, of course I can gen a new variable with strings if regiao == 1 etc., or even have build that variable (regiao) as a string since the beginning, but I thought it was easier to work along the code with numeric (makes sense, right?).
However, now that I want to use it as a string, I don't know how I can return the name of the label and not variable's name itself. Is there a good way to work this out?
Code:
gen regiao = 1 if inlist(uf, "RJ", "SP", "ES", "MG") replace regiao = 2 if inlist(uf, "SC", "RS", "PR") replace regiao = 3 if inlist(uf, "EX")
Code:
label define reg_label 1 "sudeste" 2 "sul" 3 "exterior" label values regiao reg_label
But now I want to generate some graphs using the structure foreach (below), where I want to gen a graph for each region. But inside the title, I would like that appear the name/label of the region ("sudeste", "sul", "exterior") and not the numbers (1,2,3).
Code:
levelsof regiao, local(levels) foreach l of local levels { tw line cont ano_ativ if regiao_name == "`l'" , title("Firmas ativas por Ano - `l'")
Well, of course I can gen a new variable with strings if regiao == 1 etc., or even have build that variable (regiao) as a string since the beginning, but I thought it was easier to work along the code with numeric (makes sense, right?).
However, now that I want to use it as a string, I don't know how I can return the name of the label and not variable's name itself. Is there a good way to work this out?
Comment