I have the following data structure:
id id_name date observation
1 aa 2000 1
1 aa 2001 2
1 aa 2002 1
2 dd 2000 1.5
2 dd 2001 0
2 dd 2002 1
I generate several line plots using the code below:
forvalue i = 1/300 {
graph twoway line observation date if id == `i', ///
name("graph_`i'") title("?")
}
My problem is that I don't know how to put the name of each id
(contained in the variable id_name
) as the title of each graph.
I tried achieving this with a local macro but in Stata I can't define this with an if
:
local name = id_name if id == `i'
What I managed to do is the following:
forvalue i = 1/300 {
sort id date
local title = id_name
graph twoway line observation date if id == `i', ///
name("graph_`i'") title("`title'")
drop if id == `i'
}
However, the problem of that is the elimination of the data at each step of the iteration.
If anyone could give me a piece of advice to solve this I would be very grateful.