Help for allcatplot

Description

allcatplot ensures that all predefined response categories for a variable, including those that are not present in the dataset, are included in a graph. Traditional plotting methods omit such unselected categories, potentially skewing interpretation. allcatplot uses the predefined value labels to identify and label such omitted response options and add them to the graph as zero-height bars. It also supports custom lists, labels and graph customization directly through the program syntax.

This program is especially useful for surveys and assessments utilizing likert scales or other structured response options, where it offers a holistic view of all potential responses in the graph, thereby ensuring a comprehensive understanding of the full range of response options.

Moreover, allcatplot can be used to do the opposite of what its name suggests: to exclude specific categories from the graph for clarity or analytical purposes. For instance, in a dataset with varied selections across options A, B, C, and D for a specific variable, the program can be configured to display only the responses for options A, B, and C (or any other combination of the four in any order of your choice). This doesn't eliminate the data for option D but merely hides it from the graph, with the displayed bar heights accurately reflecting the frequencies or percentages of responses for the displayed options as per the total count.

Syntax

allcatplot varlist [IF] [IN], [Over(varname)] [List(string)] [RElabel(string)] [Freq] [Sort] [Title(string)] [Missing] [Recast(string)] [Graphopts(string)]

Options

Over(varname) Specifies the variable over which to disaggregate the graphed data.

List(string) Defines a custom list of categories to include in the graph, overriding the default order and selection.

RElabel(string) Enables customization of the graph's bar labels directly through the program's syntax. To accommodate multi-word value labels, users should replace spaces with underscores (_). For instance, use "Very_Good" instead of "Very Good".

Freq Plots actual frequencies instead of percentages. Percentages remain the default option.

Sort Sorts the data in descending order.

Title(string) Customizes the title of the graph.

Missing Includes information about the number of missing observations in the dataset in the graph subtitle.

Recast(string) Changes the type of graph (e.g., from bar to hbar).

Graphopts(string) Facilitates the inclusion of additional Stata graph options. This option offers extensive customization of the graphical output.

Examples

Setting up an example dataset.

. sysuse nlsw88.dta, clear

Example 1

Demonstrating the basic functionality of plotting all categories, even those without observations.

. allcatplot race

. replace race = . if race == 3

. allcatplot race

Example 2

Editing labels and adding a custom title directly through the program syntax.

. allcatplot race, relabel(white black other) title(Race of sample population)

Example 3

Adding information about the number of missing observations as a subtitle and plotting frequencies instead of percentages.

. allcatplot race, missing

. allcatplot race, freq

Example 4

Using the recast option to change the graph type and applying additional graph options.

. allcatplot race, recast(hbar)

. allcatplot race, freq recast(dot) graphopts(ylabel(0(500)2000))

Example 5

Customizing the order of the bars and selectively displaying certain categories.

. allcatplot occupation, list(3 6 8)

. allcatplot occupation, list(8 6 3)

Including an additional option that does not occur in the dataset for illustrative purposes.

. allcatplot occupation, list(8 6 3 14) relabel(Laborers Operatives Sales Military)

Example 6

Utilizing another dataset to showcase sorting.

. sysuse auto.dta, clear

. allcatplot rep78

. allcatplot rep78, sort

Adding a bar for missing observations requires a couple of additional steps.

. tostring rep78, gen(rep78_string)

. replace rep78_string = "Missing" if rep78_string == "."

. allcatplot rep78_string, sort

Example 7

Demonstrating the 'over' option for disaggregating data by groups, including with string variables.

. sysuse auto.dta, clear

. allcatplot rep78, over(foreign) relabel(A B C D E) freq

. allcatplot rep78, over(foreign) missing freq recast(dot) graphopts(linegap(60))

. allcatplot rep78, over(foreign) sort

. decode foreign, gen(foreign_decode)

. allcatplot rep78, over(foreign_decode) missing

Notes

This program requires the elabel and splitvallabels packages for full functionality. These must be installed from SSC with the command "ssc install elabel, replace" and "ssc install splitvallabels, replace".

If the 'over' option is used, the percentages add up to 100% for each category of 'over'. In the opinion of the authors, the bars are also arranged more intutively than the traditional Stata graph bars when the 'over' option is used.

Acknowledgments

Special thanks to Daniel Klein, Nick Winter, Benn Jann and Nick Cox for writing the programs that make allcatplot possible. The name of the program is a homage to Nick Cox's catplot. Thanks to Kit Baum for his valuable advice on Stata frames and disk usage. Also, thanks to Cooper Allton, Jonathan Seiden, Ketki Samel and Sai Pitre whose feedback have been invaluable in refining allcatplot.

Authors

Kabira Namit, World Bank

knamit@worldbank.org

Zaeen de Souza, National Social Protection Secretariat - The Gambia

zaeen.desouza19_mec@apu.edu.in

Prabhmeet Kaur Matta, University of Oxford

prabhmeet.matta@economics.ox.ac.uk