
This plot recreates this one, but adds confidence intervals.
preserve
// Calculate country-specific means to be plotted
tempname foo
tempname idealage
postfile `foo' quintile incocomp incocomp_lb incocomp_ub using `foo2', replace
levelsof(quintile), local(quintile)
foreach x of local quintile {
qui reg incocomp if quintile == `x', cluster(cntry)
local incocomp = _b[_cons]
local incocomplb = _b[_cons] - (1.96 * _se[_cons])
local incocompub = _b[_cons] + (1.96 * _se[_cons])
post `foo' (`x') (`incocomp') (`incocomplb') (`incocompub')
}
postclose `foo'
// Plot country-specific means
use `foo2', clear
twoway (dot incocomp quintile) /// -twoway scatter- doesn't have the lines
(rcap incocomp_lb incocomp_ub quintile) ///
, yscale(range(1.5 3.0)) ///
ylabel(1.5 (.25) 3.0, format(%6.2f)) ///
legend(off)
title("Income quintiles")
xlabel(1 `""1" "(poorest)""' /// Double-compound quotes allow for the line break
2 3 4 5 `""5" "(richest)"') ///
fxsize(40) /// Forces x-size to be 40 percent of its original size
xtitle("") ///
xscale(range(0.2 5.8)) /// Making this a bit bigger makes room for the labels
name(byquintile_hor, replace)
restore
// Calculate country-specific means to be plotted 2
preserve
tempname foo
tempname idealage
postfile `foo' str2 cntry incocomp incocomp_lb incocomp_ub using `foo2', replace
levelsof(cntry), local(cntry)
foreach x of local cntry {
qui reg incocomp if cntry == "`x'"
local incocomp = _b[_cons]
local incocomplb = _b[_cons] - (1.96 * _se[_cons])
local incocompub = _b[_cons] + (1.96 * _se[_cons])
post `foo' ("`x'") (`incocomp') (`incocomplb') (`incocompub')
}
postclose `foo'
use `foo2', clear
// Create sorted-by-size variable
egen order_ = rank(-incocomp), unique
labmask order_, value(cntry)
// Plot country-specific means 2
twoway (dot incocomp order_) ///
(rcap incocomp_lb incocomp_ub order_) ///
, yscale(off) /// Not necessary, as we're using the one from the other graph
xlabel(1/23, val alt) ///
title("Countries") ///
xtitle("") ///
legend(off) ///
/* graphregion(margin(b=16)) */ /// Could help as -ycommon- isn't accounting for the different label sizes
name(bycntry_hor, replace)
// Combine plots
graph combine byquintile_hor bycntry_hor, ///
l1title("Mean income comparison orientation") ///
ycommon row(1) ///
imargin(zero) // Sets margin between both plots to 0
restore



