*! version 0.2 11Jul2025

help for metaxl stats

Title

metaxl stats - extract statistics to metadata files

Syntax

metaxl stats
[, options]

Options
metafile(filename) is an existing metadata file. If option save
is not set, statistics and frequencies are added to this file. The user should not
provide the file extension (.xlsx).

excludevars(varlist) sets the variables for which
the statistics will not be exported.

nofreq(varlist) sets the categorical variables
(those that have a value label) for which the frequencies will
not be exported. Set this option to _all in case you
do not want to export frequencies.

timevar(varname) provides a time variable to
compute additional statistics, namely the minimum and maximum
dates for each variable.

panelvars(varlist) computes the percentage of time invariant
observations for each variable within unique values of
varlist. The user must provide a time variable (option
timevar).

save(filename [, replace]) saves metadata, statistics and
frequencies to filename. If option metafile is not set,
the command will first extract the metadata (see metaxl extract)
to filename and then export the
statistics and frequencies. Otherwise, it copies the
contents of metafile to filename,
exporting the statistics afterwards. The user should
not provide the file extension.
Sub-option replace overwrites the file if it exists.
This option is mandatory if the user does not provide an
existing metadata file (option metafile).

stats(statistics) specifies which statistics are
to be exported. Possible statistics are the ones returned
as scalars by command summarize. By default, the command
exports the mean (mean), the standard deviation (sd), the median
(p50) and percentiles 5 and 95 (p5 and p95). Set this
option to _all to export all possible statistics.

weight(varname) sets a weighting variable to calculate the
statistics (see weight).

missdetail reports information about extended
missing values (see missing).

decimalplaces(num) sets the number of decimal places for
reported statistics. Must be an integer between 0 and 10. The default is to
export statistics as stored in Stata.

replacestats replaces statistics and frequencies
on the metadata file in case they exist.

Description

metaxl stats is a Stata command that computes variables'
statistics/frequencies and exports them to an Excel file. It is part
of the metaxl package.

The user may use an existing metadata file created with
metaxl extract (see option metafile)
and add the statistics computed from data in memory. It is also
possible to create a new file with metadata and statistics. In this case,
metaxl stats calls metaxl extract to save the
metadata and then adds the statistics.

The command skips string variables and computes the statistics for
numeric variables. The statistics reported (which may be modified) are
limited to the ones returned as scalars by command summarize. The
share of zeros, negatives and missings are also included. If the user
specifies a time variable (see option timevar), the command computes
the minimum and maximum date for each variable. It will also compute the share
of time invariant observations for each variable if the user specifies panel variables
(option panelvars).

For categorical variables (those that have a value label), an additional column named
freq_var is created in the value label worksheet. The column displays the relative
frequency for each possible level of the variable. Note that one value label may be
applied to many variables, so the number of additional columns might be greater than one.

Examples

Create metadata file with default statistics (mean sd p5 p50 p95) and save it to "meta_auto.xlsx".

. sysuse auto, clear

. metaxl stats, save(meta_auto)

Change metadata file "meta_auto.xlsx" by adding all possible statistics.

. sysuse auto, clear

. metaxl extract, meta(meta_auto)

. metaxl stats, meta(meta_auto) stats(_all)

Create metadata file "meta_nls.xlsx" with default and time statistics (min and max date and
time invariant share).

. webuse nlswork, clear

. metaxl stats, save(meta_nls) time(year) panel(idcode)

Create metadata file "meta_nls.xlsx" with default and time statistics,
except for variables idcode and year. Also, do not report levels' shares for variable
race.

. webuse nlswork, clear

. metaxl stats, save(meta_nls) time(year) panel(idcode) exc(idcode year) nof(race)

Remarks

Please notice that this software is provided "as is", without warranty of any kind, whether
express, implied, or statutory, including, but not limited to, any warranty of merchantability
or fitness for a particular purpose or any warranty that the contents of the item will be error-free.
In no respect shall the author incur any liability for any damages, including, but limited to,
direct, indirect, special, or consequential damages arising out of, resulting from, or any way
connected to the use of the item, whether or not based upon warranty, contract, tort, or otherwise.

Dependencies

gtools package by Mauricio Bravo

Author

BPLIM, Banco de Portugal, Portugal.

Email: bplim@bportugal.pt

We appreciate your feedback. Comments are welcome!