Displaying percentiles in Stata | Johan Osterberg - Product Engineer

Displaying percentiles in Stata

June 03, 2019

Sometimes you want to display the percentiles of a variable to get an idea of how values are distributed. One way of achieving this is by using the pctile command which creates a variable containing the percentiles according to specification. In order to get every 10th percentile (ie. from 10 to 90), we utilize the nquantiles option (number of quantiles) option, like so:

sysuse nlsw88, clear
pctile wage_percentiles = wage, nq(10)
list wage_percentiles in 1/10

Listing percentiles

In order to display the quartiles we can use xtile, which creates a variable containing quantile categories. Here's an example:

xtile quarters = wage, nq(4)
list wage quarters, sep(4)

Here we are displayed with a listing detailing the value of the observation (ie. the wage) as well as the corresponding quartile.


Profile picture

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin

2024 © Johan Osterberg