Stata provides the summarize command which allows you to see the mean and the standard deviation, but it does not provide the five number summary (min, q25, median, q75, max). You can use the detail option, but then you get a page of output for every variable. If you want to get the mean, standard deviation, and five number summary on one line, then you want to get the univar command. The univar command was written by John R. Gleason and appears in the Stata Technical Bulletin #51. You can download univar from within Stata by typing search univar (see How can I used the search command to search for programs and get additional help? for more information about using search).
Let’s illustrate use of the univar command using the high school and beyond data file we use in our Stata Classes.
use https://stats.idre.ucla.edu/stat/stata/notes/hsb1, clear (highschool and beyond (200 cases))
Here you see the output you get from summarize.
summarize read write math science socst Variable | Obs Mean Std. Dev. Min Max ---------+----------------------------------------------------- read | 200 52.23 10.25294 28 76 write | 200 52.775 9.478586 31 67 math | 200 52.645 9.368448 33 75 science | 195 51.66154 9.866026 26 74 socst | 200 52.405 10.73579 26 71
Here is the output you can get from univar.
univar read write math science socst -------------- Quantiles -------------- Variable n Mean S.D. Min .25 Mdn .75 Max ------------------------------------------------------------------------------- read 200 52.23 10.25 28.00 44.00 50.00 60.00 76.00 write 200 52.78 9.48 31.00 45.50 54.00 60.00 67.00 math 200 52.64 9.37 33.00 45.00 52.00 59.00 75.00 science 195 51.66 9.87 26.00 44.00 53.00 58.00 74.00 socst 200 52.40 10.74 26.00 46.00 52.00 61.00 71.00 -------------------------------------------------------------------------------
If you include the vlabel option, it also includes the variable labels in the table.
univar read write math science socst, vlabel -------------- Quantiles -------------- Variable n Mean S.D. Min .25 Mdn .75 Max ------------------------------------------------------------------------------- read reading score read 200 52.23 10.25 28.00 44.00 50.00 60.00 76.00 write writing score write 200 52.78 9.48 31.00 45.50 54.00 60.00 67.00 math math score math 200 52.64 9.37 33.00 45.00 52.00 59.00 75.00 science science score science 195 51.66 9.87 26.00 44.00 53.00 58.00 74.00 socst social studies score socst 200 52.40 10.74 26.00 46.00 52.00 61.00 71.00 -------------------------------------------------------------------------------
The boxplot option displays a mini boxplot above each variable.
univar read write math science socst, boxplot ----------:::::::::|:::::::::---------- Variable n Mean S.D. Min .25 Mdn .75 Max ------------------------------------------------------------------------------- read -----------------------::::::::|::::::::::::::----------------------- read 200 52.23 10.25 28.00 44.00 50.00 60.00 76.00 write ---------------------------::::::::::::::::|::::::::::::------------- write 200 52.78 9.48 31.00 45.50 54.00 60.00 67.00 math -------------------::::::::::::|:::::::::::-------------------------- math 200 52.64 9.37 33.00 45.00 52.00 59.00 75.00 science --------------------------::::::::::::|:::::::----------------------- science 195 51.66 9.87 26.00 44.00 53.00 58.00 74.00 socst ------------------------------:::::::::|::::::::::::::--------------- socst 200 52.40 10.74 26.00 46.00 52.00 61.00 71.00 -------------------------------------------------------------------------------
Here we use the by(female) option to display tables separately for males and females.
univar read write math science socst, by(female) -> female=male -------------- Quantiles -------------- Variable n Mean S.D. Min .25 Mdn .75 Max ------------------------------------------------------------------------------- read 91 52.82 10.51 31.00 44.00 52.00 63.00 76.00 write 91 50.12 10.31 31.00 41.00 52.00 59.00 67.00 math 91 52.95 9.66 35.00 45.00 52.00 60.00 75.00 science 86 52.88 10.75 26.00 44.00 55.00 61.00 74.00 socst 91 51.79 11.33 26.00 46.00 51.00 61.00 71.00 ------------------------------------------------------------------------------- -> female=female -------------- Quantiles -------------- Variable n Mean S.D. Min .25 Mdn .75 Max ------------------------------------------------------------------------------- read 109 51.73 10.06 28.00 44.00 50.00 57.00 76.00 write 109 54.99 8.13 35.00 50.00 57.00 62.00 67.00 math 109 52.39 9.15 33.00 45.00 53.00 58.00 72.00 science 109 50.70 9.04 29.00 44.00 50.00 58.00 69.00 socst 109 52.92 10.23 26.00 46.00 56.00 61.00 71.00 -------------------------------------------------------------------------------
We can use the by(female) and onehdr options to get a table with one header that can be a bit easier to read.
univar read write math science socst, by(female) onehdr -------------- Quantiles -------------- Variable n Mean S.D. Min .25 Mdn .75 Max ------------------------------------------------------------------------------- -> female=male read 91 52.82 10.51 31.00 44.00 52.00 63.00 76.00 write 91 50.12 10.31 31.00 41.00 52.00 59.00 67.00 math 91 52.95 9.66 35.00 45.00 52.00 60.00 75.00 science 86 52.88 10.75 26.00 44.00 55.00 61.00 74.00 socst 91 51.79 11.33 26.00 46.00 51.00 61.00 71.00 -> female=female read 109 51.73 10.06 28.00 44.00 50.00 57.00 76.00 write 109 54.99 8.13 35.00 50.00 57.00 62.00 67.00 math 109 52.39 9.15 33.00 45.00 53.00 58.00 72.00 science 109 50.70 9.04 29.00 44.00 50.00 58.00 69.00 socst 109 52.92 10.23 26.00 46.00 56.00 61.00 71.00 -------------------------------------------------------------------------------
Here we ask for a boxplot for the variable write and ask that the boxplots be plotted using the same scale (via onescal) so we could meaningfully compare the boxplot of the males and females. You can see that the median of the boxplot is higher for the females. (If we had omitted the onescal option, each boxplot would be on its own scale).
univar write , by(female) onehdr boxplot onescal ----------:::::::::|:::::::::---------- Variable n Mean S.D. Min .25 Mdn .75 Max ------------------------------------------------------------------------------- -> female=male write -------------------:::::::::::::::::::::|:::::::::::::--------------- write 91 50.12 10.31 31.00 41.00 52.00 59.00 67.00 -> female=female write ----------------------------:::::::::::::|::::::::::--------- write 109 54.99 8.13 35.00 50.00 57.00 62.00 67.00 -------------------------------------------------------------------------------
For More Information
For more information, see the help or reference manual about summarize.