help fre
-------------------------------------------------------------------------------

Title

fre -- One-way frequency tables

Syntax

fre varlist [if] [in] [weight] [, options ]

fre varlist using filename [if] [in] [weight] [, options export_opts ]

options Description ------------------------------------------------------------------------- format(#) decimal places for percentages; default is 2 fformat(%fmt) display format for frequencies; default is %9.0g tabulate(#) tabulate # smallest and # largest values; default is 20 rows(#) tabulate # rows; equivalent to tabulate(#/2) all tabulate all values; ignore tabulate() and rows() nomissing omit missing values nolabel omit labels novalue omit values noname omit variable name notitle omit title containing variable name and label nowrap do not wrap the labels truncate truncate the labels width(#) maximum width of labels column; default is 50 minwidth(#) minimum width of labels column includelabeled include all labeled values include(numlist) include all values in numlist subpop(varname) exclude observations for which varname = 0 ascending display rows in ascending order of frequency descending display rows in descending order of frequency order display tables in alphabetical order of varlist -------------------------------------------------------------------------

export_opts Description ------------------------------------------------------------------------- tab export tab-delimited table (default) tex export LaTeX-formated table bodyonly export table body only (omit header) combine place codes and labels in same cell pre(strlist) text to be printed before the table post(strlist) text to be printed after the table replace overwrite existing file append append to existing file -------------------------------------------------------------------------

by is allowed; see help by. fweights and aweights are allowed; see help weight.

Description

fre displays for each specified variable a univariate frequency table containing counts, overall percent, "valid" percent (i.e. percent based on non-missing observations), and cumulative percent. Variables may be string or numeric. Labels, in full length, and values are printed. By default, fre tabulates only the smallest and largest 20 values (along with all missing values), but this can be changed using the tabulate(), rows(), or all option. Furthermore, you may include values with zero observed frequency using the includelabeled, include(), and subpop() options.

The default for fre is to display the frequency tables in the results window and the log. Alternatively, if using is specified, the tables are written to a file on disk, either tab-delimited (default) or LaTeX-formatted (see the tex option).

Options

+----------------+ ----+ common_options +---------------------------------------------------

format(#) sets the number of decimal places displayed for percentages. The default is format(2).

fformat(%fmt) sets the display format for frequencies; see help format. The default is fformat(%9.0g).

tabulate(#) causes only the # smallest and the # largest values to be tabulated. The default is tabulate(20). All values are tabulated if # < 1, or # = ., or if the all option is specified.

rows(#) causes only the #/2 smallest and #/2 largest values to be tabulated. rows(#) is a equivalent to tabulate(#/2). rows() has no effect if tabulate() is specified.

all causes all observed values to be tabulated. all takes precedence over tabulate() and rows().

nomissing requests that missing values be excluded. The "valid" percent column will be suppressed in this case.

nolabel requests that the value labels (and the variable label) be omitted.

novalue requests that only the value labels be printed, but not the associated numeric values (unless a specific value label is empty). This option has no effect if used with sting variables.

noname requests that, if a variable label is available, only the variable label be printed in the table's caption.

notitle requests that the table's caption containing the variable name and label be omitted.

nowrap requests that long labels not be wrapped. The default is to wrap labels that do not fit in the maximum width of the labels column (see the width() option). For screen display, nowrap causes long labels to be truncated instead of wrapped. For export to file (i.e. if using is specified), nowrap causes labels to be printed in full length in one line.

truncate requests that long labels be truncated to width(). (Note that, for screen display, truncate and nowrap have the same effect.)

width(#) sets the maximum width of the labels column. The default is width(50). For display in the results window, the actual maximum may be less than the specified value depending on the current width of the screen (see linesize).

minwidth(#) set the minimum width of labels column. Setting minwidth() to the value of width() produces a table with a fixed labels column width. minwidth() has no influence if using is specified.

includelabeled causes labeled values (i.e. values for which a label is defined) to be included in the table even if they do not occur in the dataset (i.e. if they have zero observed frequency). (Observed values will always be tabulated, whether labeled or not, unless they are excluded using the if qualifier).

include(numlist) causes all values in numlist to be included in the table even if they do not occur in the dataset (i.e. if they have zero observed frequency). Missing values (e.g. ., .a) are allowed in numlist. (All other observed values will also be tabulated unless excluded using the if qualifier).

subpop(varname) excludes observations for which varname = 0 in computing the frequency counts, but includes them in determining the table rows. Values that are observed in the varname = 0 group but not in the varname = 1 group will be shown as having 0 frequency.

ascending displays the table rows in ascending order of frequency. The order of the missing values is kept as is.

descending displays the table rows in descending order of frequency (and ascending order of the variable's values within equal frequency rows). The order of the missing values is kept as is.

order displays the tables in alphabetical order of varlist.

+-------------+ ----+ export_opts +------------------------------------------------------

tab uses the tab-character as a column delimiter in the stored table. This is the default unless filename has a ".tex" suffix.

tex formats the stored table for use with LaTeX. This is the default if filename has a ".tex" suffix. The "_" character in variable names will be replaced by "\_".

bodyonly requests that only the table body containing the frequency distribution be stored.

combine requests that values and labels be placed in the same cell. The default is to place values and labels in separate cells (i.e. to print a column delimiter between values and labels).

pre(strlist) and post(strlist) specify lines of text to be printed before and after the table. Use double quotes to separate the lines. For example, post("" "some text") would insert a blank line followed by a line containing some text. Use compound double quotes (`"..."') for lines containing double quotes.

replace permits overwriting an existing file.

append causes output to be appended to an existing file.

Examples

. sysuse auto, clear (1978 Automobile Data)

. fre foreign foreign -- Car type ---------------------------------------------------------------- | Freq. Percent Valid Cum. -------------------+-------------------------------------------- Valid 0 Domestic | 52 70.27 70.27 70.27 1 Foreign | 22 29.73 29.73 100.00 Total | 74 100.00 100.00 ----------------------------------------------------------------

. fre rep78 rep78 -- Repair Record 1978 ----------------------------------------------------------- | Freq. Percent Valid Cum. --------------+-------------------------------------------- Valid 1 | 2 2.70 2.90 2.90 2 | 8 10.81 11.59 14.49 3 | 30 40.54 43.48 57.97 4 | 18 24.32 26.09 84.06 5 | 11 14.86 15.94 100.00 Total | 69 93.24 100.00 Missing . | 5 6.76 Total | 74 100.00 -----------------------------------------------------------

. fre rep78, subpop(foreign) rep78 -- Repair Record 1978 ----------------------------------------------------------- | Freq. Percent Valid Cum. --------------+-------------------------------------------- Valid 1 | 0 0.00 0.00 0.00 2 | 0 0.00 0.00 0.00 3 | 3 13.64 14.29 14.29 4 | 9 40.91 42.86 57.14 5 | 9 40.91 42.86 100.00 Total | 21 95.45 100.00 Missing . | 1 4.55 Total | 22 100.00 -----------------------------------------------------------

. label define origin .a "unknown", modify . fre foreign, includelabeled foreign -- Car type ----------------------------------------------------------------- | Freq. Percent Valid Cum. --------------------+-------------------------------------------- Valid 0 Domestic | 52 70.27 70.27 70.27 1 Foreign | 22 29.73 29.73 100.00 Total | 74 100.00 100.00 Missing .a unknown | 0 0.00 Total | 74 100.00 -----------------------------------------------------------------

. label define rep 1 "This long label will be wrapped" . label value rep78 rep . fre rep78, width(15) include(1/7 .a .b .c) rep78 -- Repair Record 1978 ------------------------------------------------------------------- | Freq. Percent Valid Cum. ----------------------+-------------------------------------------- Valid 1 This long | 2 2.70 2.90 2.90 label will | be wrapped | 2 | 8 10.81 11.59 14.49 3 | 30 40.54 43.48 57.97 4 | 18 24.32 26.09 84.06 5 | 11 14.86 15.94 100.00 6 | 0 0.00 0.00 100.00 7 | 0 0.00 0.00 100.00 Total | 69 93.24 100.00 Missing . | 5 6.76 .a | 0 0.00 .b | 0 0.00 .c | 0 0.00 Total | 5 6.76 Total | 74 100.00 -------------------------------------------------------------------

. fre price, nomissing price -- Price ------------------------------------------ | Freq. Percent Cum. --------+--------------------------------- 3,291 | 1 1.35 1.35 3,299 | 1 1.35 2.70 3,667 | 1 1.35 4.05 3,748 | 1 1.35 5.41 3,798 | 1 1.35 6.76 3,799 | 1 1.35 8.11 3,829 | 1 1.35 9.46 3,895 | 1 1.35 10.81 3,955 | 1 1.35 12.16 3,984 | 1 1.35 13.51 3,995 | 1 1.35 14.86 4,010 | 1 1.35 16.22 4,060 | 1 1.35 17.57 4,082 | 1 1.35 18.92 4,099 | 1 1.35 20.27 4,172 | 1 1.35 21.62 4,181 | 1 1.35 22.97 4,187 | 1 1.35 24.32 4,195 | 1 1.35 25.68 4,296 | 1 1.35 27.03 : | : : : 6,303 | 1 1.35 74.32 6,342 | 1 1.35 75.68 6,486 | 1 1.35 77.03 6,850 | 1 1.35 78.38 7,140 | 1 1.35 79.73 7,827 | 1 1.35 81.08 8,129 | 1 1.35 82.43 8,814 | 1 1.35 83.78 9,690 | 1 1.35 85.14 9,735 | 1 1.35 86.49 10,371 | 1 1.35 87.84 10,372 | 1 1.35 89.19 11,385 | 1 1.35 90.54 11,497 | 1 1.35 91.89 11,995 | 1 1.35 93.24 12,990 | 1 1.35 94.59 13,466 | 1 1.35 95.95 13,594 | 1 1.35 97.30 14,500 | 1 1.35 98.65 15,906 | 1 1.35 100.00 Total | 74 100.00 ------------------------------------------

. fre foreign using test.tex (output written to test.tex)

. type test.tex

foreign --- Car type

\begin{tabular}{lllrrrr}\hline & & & Freq. & Percent & Valid & Cum. \\ \hline Valid & 0 & Domestic & 52 & 70.27 & 70.27 & 70.27 \\ & 1 & Foreign & 22 & 29.73 & 29.73 & 100.00 \\ & Total & & 74 & 100.00 & 100.00 & \\ \hline\end{tabular} . fre foreign using test.tex, bodyonly replace /// > pre("\begin{table}\caption{Car Type}" /// > "\begin{tabular}{lllrrrr}" /// > "&&Freq.&Per.&Val. Per.&Cum. Per\\") /// > post("\end{tabular}\end{table}") (output written to test.tex)

. type test.tex \begin{table}\caption{Car Type} \begin{tabular}{lllrrrr} &&Freq.&Per.&Val. Per.&Cum. Per\\ Valid & 0 & Domestic & 52 & 70.27 & 70.27 & 70.27 \\ & 1 & Foreign & 22 & 29.73 & 29.73 & 100.00 \\ & Total & & 74 & 100.00 & 100.00 & \\ \end{tabular}\end{table}

Returned results

Scalars:

r(N) number of observations r(N_valid) number of nonmissing observations r(N_missing) number of missing observations r(r) number of rows (values, categories, levels) r(r_valid) number of nonmissing rows r(r_missing) number of missing rows

Macros:

r(depvar) name of tabulated variable r(label) label of tabulated variable r(lab_valid) row labels of nonmissing values r(lab_missing) row labels of missing values

Matrices:

r(valid) frequency counts of nonmissing values r(missing) frequency counts of missing values

Author

Ben Jann, University of Bern, jann@soz.unibe.ch

Thanks for citing this software as follows:

Jann, B. (2007). fre: Stata module to display one-way frequency table. Available from http://ideas.repec.org/c/boc/bocode/s456835.html.

Also see