Creating a bar graph for categorical variables in Stata

I have written a small command that allows you to import a table you have created into Stata as a frame dataset. This command works for Stata version 17 and above. I have called the program colframe and you can download it here. Place this file in your personal ado directory to use it.

This file can be useful for creating bar graphs from summarized data. You will find the commands to create this graph below.

sysuse auto, clear
generate mpg1 = mpg < 30
recode mpg (min/25 = 0) (26/30 = 1) (31/max = 2), generate(mpg2)
rename foreign mpg3

table () (result), statistic(fvfrequency mpg1 mpg2 mpg3) statistic(fvproportion mpg1 mpg2 mpg3)
collect style row split, nodelimiter nospacer dups(repeat) position(left) span
collect style header, level(value) title(hide)

colframe graph, collection(Table) firstrow replace

rename (a b) (type category)
graph bar (mean) fvproportion, over(category, sort(category)) over(type) showyvars asyvar legend(off) ytitle("Proportion")

You may find more useful information in the book A Visual Guide to Stata Graphics