I would like to draw a confidence ellipse (sometimes also called concentration ellipse) for two continuous variables using Stata.
There is a community-contributed command called ellip
for this kind of graph, a detailed description of which is provided by its author Anders Alexandersson on Stata Journal. However, I would like to apply weights for the ellipse which is not possible using this command.
Below is a reproducible example where I try to plot the number of marriages per 1000
inhabitants over the percentage of urban population in US states using the population size as a weight:
clear all
sysuse census
gen marpop = marriage / pop * 1000
gen urbpop = popurban / pop * 100
ellip marpop urbpop if state2!="NV", plot(scatter marpop urbpop if state2!="NV") ///
name(ellip_noaw)
ellip marpop urbpop if state2!="NV", plot(scatter marpop urbpop [aw=pop] if state2!="NV") ///
name(ellip_aw)
graph combine ellip_noaw ellip_aw
The results look as follows:
As you can see the second ellipse, where the points of the scatter plot are weighted/inflated by the population size, should be possibly shifted to the bottom-right.
How can I create a weighted confidence ellipse in Stata?