*! version 0.1.4 23Jan2019

Title

gstats winsor -- Winsorize data using C for speed

Important: Please run gtools, upgrade to update gtools to
the latest stable version.

Syntax

gstats winsor was written as a fast winsor2 alternative. It
additionally accepts weights.

gstats winsor
varlist
[if] [in]
[weight]
[, by(varlist) options]

Winsor Options
prefix(str) Generate targets as prefixsource (default empty).

suffix(str) Generate targets as sourcesuffix (default _w with cut and _tr with trim).

generate(namelist) Named targets to generate; one per source.

cuts(#.# #.#) Cut points (detault 1.0 and 99.0 for 1st and 99th percentiles).

trim Trim instead of Winsorize (i.e. replace outliers with missing values).

label Add Winsorized/trimming note to target labels.

replace Replace targets if they exist.

nomissing With by(), ignore groups with missing entries.

Gtools Options
compress Try to compress strL to str#.

forcestrl Skip binary variable check and force gtools to read strL variables.

verbose Print info during function execution.

bench[(int)] Benchmark various steps of the plugin. Optionally specify depth level.

hashmethod(str) Hash method (default, biject, or spooky). Intended for debugging.

oncollision(str) Collision handling (fallback or error). Intended for debugging.

aweights, fweights, iweights, and pweights are
allowed (see [U] 11.1.6 weight for more on the way Stata
uses weights).

Description

gstats winsor winsorizes or trims (if the trim option is specified)
the variables in varlist at particular percentiles specified by option
cuts(#1 #2). By defult, new variables will be generated with a
suffix "_w" or "_tr", respectively. The user can control this via the
suffix() option. The replace option replaces the variables with
their winsorized or trimmed ones.

Difference between winsorizing and trimming

Important: This section is nearly verbatim from the equivalent help
section from winsor2.

Winsorizing is not equivalent to simply excluding data, which is
a simpler procedure, called trimming or truncation. In a trimmed
estimator, the extreme values are discarded; in a Winsorized estimator,
the extreme values are instead replaced by certain percentiles,
specified by option cuts(# #). For details, see winsor (if
installed), and trimmean (if installed).

For example, you type the following commands to get the 1st and 99th
percentiles of the variable wage, 1.930993 and 38.70926.

. sysuse nlsw88, clear

. sum wage, detail

By default, gstats winsor winsorizes wage at 1st and 99th percentiles,

. gstats winsor wage, replace cuts(1 99)

which can be done by hand:

. replace wage=1.930993 if wage<1.930993

. replace wage=38.70926 if wage>38.70926

Note that, values smaller than the 1st percentile are repalced by that
value, and similarly with values above the 99th percentile. When the
-trim- option is specified, those values are set to missing instead
(which are discarded by most commands):

. gstats winsor wage, replace cuts(1 99) trim

which can also be done by hand:

. replace wage=. if wage<1.930993

. replace wage=. if wage>38.70926

In this case, we discard values smaller than 1th percentile or greater
than 99th percentile. This is trimming.

Examples

See the
online documentation
for examples.

Author

Mauricio Caceres

mauricio.caceres.bravo@gmail.com

mcaceresb.github.io

Website

gstats is maintained as part of the [R] gtools project at github.com/mcaceresb/stata-gtools

Acknowledgment

gstats winsor was written largely to mimic the functionality of the community-contributed command winsor2.

Yujun,Lian (Arlion) Department of Finance, Lingnan College, Sun Yat-Sen University.

E-mail: arlionn@163.com.

Blog: http://blog.cnfol.com/arlion.

Homepage: http://www.lingnan.sysu.edu.cn/lnshizi/faculty_vch.asp?name=lianyj.

This, in turn, had incorporated some code from winsor, by

Nicholas J. Cox, Durham University, U.K.

n.j.cox@durham.ac.uk

and winsorizeJ.ado, by

Judson Caskey

gstats winsor's options and this helpfile borrow heavily from winsor2.

gtools was largely inspired by Sergio Correia's ftools:
https://github.com/sergiocorreia/ftools.

The OSX version of gtools was implemented with invaluable help from @fbelotti;
see https://github.com/mcaceresb/stata-gtools/issues/11.

Also see

help for
gtools;
winsor2 (if installed)