. webuse set "https://raw.githubusercontent.com/kho777/data-visualization/master
> /data"
(prefix now "https://raw.githubusercontent.com/kho777/data-visualization/master/
> data")
. webuse "hpi2016dataonly", clear
Taking the log of GDP Per capita to make the variable more linear.
. gen lgdp=log(GDPcapitaPPP)
. label variable lgdp "GDP Per Capita (logged)"
Create multiple variables for plots of Happy Planet Index using Region. Use the label statements to clean and shorten the variable labels for legend
. separate HappyPlanetIndex, by(Region) shortlabel
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------
HappyPlanetIn~1 double %10.0g Region == Americas
HappyPlanetIn~2 double %10.0g Region == Asia Pacific
HappyPlanetIn~3 double %10.0g Region == Europe
HappyPlanetIn~4 double %10.0g Region == Middle East and North
Africa
HappyPlanetIn~5 double %10.0g Region == Post-communist
HappyPlanetIn~6 double %10.0g Region == Sub Saharan Africa
. lab var HappyPlanetIndex1 "Americas"
. lab var HappyPlanetIndex2 "Asia Pacific"
. lab var HappyPlanetIndex3 "Europe"
. lab var HappyPlanetIndex4 "Middle East and North Africa"
. lab var HappyPlanetIndex5 "Post-communist"
. lab var HappyPlanetIndex6 "Sub Saharan Africa"
. scatter HappyPlanetIndex? lgdp, ytitle(Happy Planent Index)
. regress HappyPlanetIndex lgdp
Source | SS df MS Number of obs = 140
-------------+---------------------------------- F(1, 138) = 9.28
Model | 469.252954 1 469.252954 Prob > F = 0.0028
Residual | 6974.55558 138 50.5402578 R-squared = 0.0630
-------------+---------------------------------- Adj R-squared = 0.0562
Total | 7443.80853 139 53.5525794 Root MSE = 7.1092
------------------------------------------------------------------------------
HappyPlane~x | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lgdp | 1.2505 .4103919 3.05 0.003 .4390302 2.061969
_cons | 15.65245 3.58156 4.37 0.000 8.570619 22.73428
------------------------------------------------------------------------------
The regression shows that for every unit increase in GDP Per Capita (logged), a 1.2505 unit increase in Happy Planet Index is predicted.