Hi all,

I'm using panel data on public debt from 1980 to 2015. What I would like to do is a xtline overlay graph with attached country names for the highest debt in the first and in the last period.
I did it manualy, and it looks like this:

Array

I did it using the following commands

Code:
* identifying countries with highest debt
summarize debt_snde if year==2015 
local max = r(max)
tabulate countryWDI if debt_snde == r(max) & year ==2015 
summarize debt_snde if year==1980
tabulate countryWDI if debt_snde == r(max) & year ==1980
sort country year

* plotting the data
xtline debt_snde if year>=1980 , overlay  legend(off) note("All Countries") ytitle("Debt to GDP ratio") ///
   tlabel(1980(5)2015) ylabel(,format(%14.0fc)) ttext(`max' 2015 "JPN" 318.93 1980 "GUY", place(n))
graph export "fig1-a.png", as(png) replace
I use summarize to identify maximum, and then tabulate to identify a country name. As you can see, I hard coded country name in the ttext option. What I would like to do is automate it in a way that the first and the last period are selected automatically (1980 and 2015) and that I can automatically select the country name.

Any help would be appreciated!

Thank you,

Vladimir