*! version 1.1 for version 1.1 of -compare2.ado- 30Nov2021 by Mead Over

*! Hack of Stata's -compare.ado- version 2.2.8 17dec2020

Title

compare2 -- Compare two variables - and return the results

Syntax

compare2
varname1
varname2
[if] [in]
[, reldif]

by is allowed; see [D] by.

Option

reldif compute the relative differences between varname1 and
varname2 and display the summary statistics of the differences.
This option requires that both variables be numeric.

width(integer) specify the width of the results display.
The default is 80 columns (wider than compare's display width of 72 columns).

Description

Like Stata's compare, compare2 reports the differences and similarities
between varname1 and varname2. However, unlike compare,
compare2 also returns the results in return
for subsequent use by the programmer.

The reldif option asks compare2
to calculate the relative differences between varname1 and varname2
as computed by the Stata function reldif and then display the summary statistics
of the relative differences over the sample.
The mean relative difference between the two variables, as well as the other
summary statistics describing the relative differences, are returned.

Also compare2 widens the default display width from 72 to 80 columns
and allows the user to specify an even wider display with the option width(integer).
Additional display columns improve the legibility of the results by allowing
longer abreviations for the names of the compared variables.

Examples

Setup

. webuse fullauto

Report differences between rep77 and rep78

. compare2 rep77 rep78

difference

count minimum average maximum

rep77<rep78 16 -3 -1.3125 -1
rep77=rep78 43
rep77>rep78 7 1 1 1

jointly defined 66 -3 -.2121212 1
rep77 missing only 3
jointly missing 5

total 74

Adding the reldif option elicits additional output.

. compare2 rep77 rep78, reldif

difference

count minimum average maximum

rep77<rep78 16 -3 -1.3125 -1
rep77=rep78 43
rep77>rep78 7 1 1 1

jointly defined 66 -3 -.2121212 1
rep77 missing only 3
jointly missing 5

total 74

Summary statistics of the relative difference between rep77 and rep78,
defined as reldif( rep77 , rep78 ). See help reldif

Variable | Obs Mean Std. Dev. Min Max

+

__000004 | 66 .095202 .1474213 0 .5

These results can be retrieved using the command return list.

. return list

scalars:
r(sum) = 6.283333333333333
r(max) = .5
r(min) = 0
r(sd) = .1474212857189744
r(Var) = .0217330354830355
r(mean) = .0952020202020202
r(sum_w) = 66
r(N) = 66

macros:
r(jnt1lt2) : "16"
r(min1lt2) : "-3"
r(mn1lt2) : "-1.3125"
r(max1lt2) : "-1"
r(jnteq) : "43"
r(jnt1gt2) : "7"
r(min1gt2) : "1"
r(mn1gt2) : "1"
r(max1gt2) : "1"
r(joint) : "66"
r(minjnt) : "-3"
r(mnjnt) : "-.2121212121212121"
r(maxjnt) : "1"
r(v1msng) : "3"
r(v2msng) : "0"
r(bthmsng) : "5"
r(total) : "74"

Returned results

The command return list displays the returned results. After the
prefix by or bysort, only the results from the last by group
are returned.

macros:
r(jnt1lt2) : Count of observations when variable 1 is less than variable 2
r(min1lt2) : Minimum when variable 1 is less than variable 2
r(mn1lt2) : Mean when variable 1 is less than variable 2
r(max1lt2) : Maximum when variable 1 is less than variable 2
r(jnteq) : Count of observations when variable 1 is equal to variable 2
r(jnt1gt2) : Count of observations when variable 1 is greater than variable 2
r(min1gt2) : Minimum when variable 1 is greater than variable 2
r(mn1gt2) : Mean when variable 1 is greater than variable 2
r(max1gt2) : Maximum when variable 1 is greater than variable 2
r(joint) : Count of observations when neither variable is missing
r(minjnt) : Minimum when neither variable is missing
r(mnjnt) : Mean when neither variable is missing
r(maxjnt) : Maximum when neither variable is missing
r(v1msng) : Count of observations when only variable 1 is missing
r(v2msng) : Count of observations when only variable 2 is missing
r(bthmsng) : Count of observations when both variables missing
r(total) : Count of total observations

If the option reldif is selected, compare2 also returns the results
of executing the summarize command on the computed relative differences
between the two variables. See help reldif.

scalars:
r(sum)
r(max)
r(min)
r(sd)
r(Var)
r(mean)
r(sum_w)
r(N)

Author

Mead Over at:
Email: MOver@CGDev.Org if you observe any
problems.