sysuse lifeexp, clear
keep if region==2 | region==3
replace gnppc = gnppc / 1000
label var gnppc "GNP per capita (thousands of dollars)"
gen lgnp = log(gnp)
qui reg lexp lgnp
predict hat 
label var hat "Linear prediction"
replace country = "Trinidad" if country=="Trinidad and Tobago"
replace country = "Para" if country == "Paraguay"
gen pos = 3 
replace pos = 9 if lexp > hat 
replace pos = 3 if country == "Colombia"
replace pos = 3 if country == "Para"
replace pos = 3 if country == "Trinidad"
replace pos = 9 if country == "United States"

#delimit ;

twoway
(scatter lexp gnppc, mlabel(country) mlabv(pos))
(line hat gnppc, sort)
, xsca(log) xlabel(.5 5 10 15 20 25 30, grid) legend(off) 
  title("Life expectancy vs. GNP per capita") 
  subtitle("North, Central, and South America") 
  note("Data source:  World bank, 1998") 
  ytitle("Life expectancy at birth (years)")
;
#delimit cr