help for rround

Random rounding to base 3

Syntax

rround varlist
[using filename]
[,
harmonize
]

Description

rround randomly rounds values up or down to the nearest multiple of 3.
Values are rounded to the nearest multiple of 3 with a probability of 2/3,
and the second nearest multiple with a probability of 1/3. Values that are
already multiples of 3 are left unchanged.

For each variable provided in varlist, rround generates an additional
variable named the same but with the suffix _rr. Each observation of the new variables is a
randomly rounded value of the corresponding observation in the provided variable.
The variables provided in varlist are left unchanged.

There are three different modes. Without any option, rround randomly rounds
each value independently. With the option harmonize, the program will round
the same values across the provided variables in the same direction. When providing a filename,
rround will use this file to save pairs that contain unrounded and the randomly rounded values,
and use the same randomly rounded value every time the same unrounded value comes up.
This allows consistent rounding in the same direction across Stata sessions and datasets.
The program uses
Stata's data frames and therefore requires Stata version 16 or later.

Options

harmonize rounds the same values within one variable in the same direction.
This is achieved by using the first obtained random round for all cases. Note that the same value in different
variables may be rounded to different multiples of 3.

using filename creates and saves a Stata dataset with the provided name,
containing pairs of unrounded and randomly rounded values. For each unrounded value,
rround checks if the value is already included in filename, and uses the
corresponding rounded value if this is the case. If not, it will use a newly generated
random round and write the pair to filename.
If filename already exists, it will use all included unrouded-rounded pairs, append newly
generated unrounded-rounded pairs as necessary and overwrite filename with the updated file.

Examples

This example uses collapse to produce counts of a categorial variable. Then, the corresponding
randomly rounded counts are generated with rround.

sysuse auto
gen count=1
collapse (sum) count, by(rep78)
rround count
list

+----------------
+
| rep78 count count_rr |
+----------------
+
1. | 1 2 3 |
2. | 2 8 9 |
3. | 3 30 30 |
4. | 4 18 18 |
5. | 5 11 9 |
+----------------
+
6. | . 5 6 |
+----------------
+

This example uses Stata's data frames to collect the results of two t-tests,
and rround to round the number of involved observations.
Note that rround here rounds the same count
of the same variable in the same direction because of the harmonize option.

sysuse auto
frame create tframe str10 varname mean1 count1 mean2 count2 pvalue
ttest price, by(foreign)
frame post tframe ("price") (`r(mu_1)') (`r(N_1)') (`r(mu_2)') (`r(N_2)') (`r(p)')
ttest mpg, by(foreign)
frame post tframe ("mpg") (`r(mu_1)') (`r(N_1)') (`r(mu_2)') (`r(N_2)') (`r(p)')
frame change tframe
rround count1 count2, harmonize
list, ab(9)

+
-
----------
----------
-
-
+
| varname mean1 count1 mean2 count2 pvalue count1_rr count2_rr |
+
-
----------
----------
-
-
+
1. | price 6072.423 52 6384.682 22 .6801851 54 21 |
2. | mpg 19.82692 52 24.77273 22 .0005254 54 21 |
+
-
----------
----------
-
-
+

This example uses the Stata ado parmest (available at SSC) to store three estimation results in Stata datasets on disk.
Then, the datasets are loaded and rround rounds the regressions' number of observations. The program is called with
the using filename syntax, so the rounding happens consistently in the same direction, and an additional Stata
dataset autoround.dta is saved with the two pairs of unrounded and rounded counts.

sysuse auto
reg price mpg
parmest, saving(model1, replace) escal(N) ylabel idstr(simple)
reg price mpg weight
parmest, saving(model2, replace) escal(N) ylabel idstr(adjusted)
reg price mpg weight if foreign==0
parmest, saving(model3, replace) escal(N) ylabel idstr(domestic)
use model1
append using model2
append using model3
rename es_1 count
rround count using autoround.dta
list idstr estimate stderr count count_rr if parm=="mpg"

+
-
-
---------
+
| idstr estimate stderr count count_rr |
+
-
-
---------
+
1. | simple -238.89435 53.076687 74 72 |
3. | adjusted -49.512221 86.156039 74 72 |
6. | domestic 237.69095 139.03342 52 51 |
+
-
-
---------
+

Author

Thomas Schober, Auckland University of Technology

thomas.schober@aut.ac.nz