-------------------------------------------------------------------------------
help for quantiles
-------------------------------------------------------------------------------

Categorize by quantiles

quantiles varname [weight] [if exp] [in range], gencatvar(newvar) [nquant(#) keeptog(varname) stable]

by ... : may be used with quantiles; see help by.

fweight, aweight and iweight are allowed; see help weights.

Description

quantiles creates a new variable (newvar) that categorizes varname by its quantiles. It differs from xtile because the categories are defined by the ideal size of the quantile rather than by the cutpoints, therefore yielding less unequaly sized categories when the cutpoint value is frequent, when using weights or when the number of observations in the dataset is not a product of the number of quantiles. It may not work properly on small datasets or if calculated for small groups. If the number of observations in the dataset or group is small, tabulate newvar afterwards to check the results.

Options

gencatvar(newvar) specifies the new variable to be generated.

nquant(#) specifies the number of quantiles; # must be an integer and greater than or equal to 2. If not specified default is 10 quantiles.

keeptog(varname) specifies that all cases within a group defined by varname should be kept together in the same quantile. This option might make more unequal the size of the quantiles. Useful, for instance, when working with household surveys to avoid having members of a single household belonging to different quantiles.

stable specifies that the internal sort will use the stable option of the sort command.

Examples

. quantiles ypercap, gen(deciles) . quantiles ypercap [w=weight], gen(tenths) . quantiles ypercap [w=weight], gen(fifths) n(5) . quantiles ypercap [w=weight], gen(hundredths) n(100) k(hhkey) . bysort econact: quantiles ylabtot [w=weight], gen(tenthlab) . quantiles ypercap [w=weight] if literacy==1, gen(centlite) n(100)

For the sake of comparison, see below the result of categorizing the weighted distribution of main occupation's earnings from the Brazilian 2005 National Household Survey using xtile and using quantiles

xtile:

ymainoccu | Freq. Percent Cum. ------------+----------------------------------- 1 | 10,253,932 12.05 12.05 2 | 6,877,819 8.08 20.14 3 | 8,392,821 9.87 30.00 4 | 11,396,936 13.40 43.40 5 | 9,535,935 11.21 54.61 6 | 4,600,509 5.41 60.02 7 | 10,515,418 12.36 72.38 8 | 6,738,072 7.92 80.30 9 | 9,694,872 11.40 91.69 10 | 7,066,854 8.31 100.00 ------------+----------------------------------- Total | 85,073,168 100.00

quantiles:

ymainoccu | Freq. Percent Cum. ------------+----------------------------------- 1 | 8,507,057 10.00 10.00 2 | 8,507,047 10.00 20.00 3 | 8,507,667 10.00 30.00 4 | 8,506,796 10.00 40.00 5 | 8,507,913 10.00 50.00 6 | 8,507,231 10.00 60.00 7 | 8,507,440 10.00 70.00 8 | 8,507,315 10.00 80.00 9 | 8,506,894 10.00 90.00 10 | 8,507,808 10.00 100.00 ------------+----------------------------------- Total | 85,073,168 100.00

Author

Rafael Guerreiro Osorio International Poverty Centre/UNDP http://www.undp-povertycentre.org/ SBS Quadra 01 Bloco J Ed. BNDES 10 Andar 700076-900, Brasilia, DF, BRAZIL

Also see

Online: help for pctile, centile, summarize