help bdiffv 14Aug2025, blog

Title

bdiffv —— Extended commands for bdiff, visualizing differences (Bootstrap and Permutaion tests) between two groups.

Syntax

bdiffv,
group:(groupvar)
model:(string)
[bdiff_options]
[bdiffv_options]

(bdiff) Main
group(varname) specify a dummy variable to tag the sample into two groups.

model(string) define the regression model, e.g., model(reg y x).

(bdiff) Test parameters
reps(#) set number of repetitions to #. Defult is 100.

seed(#) set random-number seed to #.

bsample use bootstrap sample (sampling with replacement) to perform Fisher's Permuation test. In default, bdiff uses the original sample to perform the Fisher's Permuation test.

surtest perform SUR test, see suest.

(bdiff) Reporting
first report the coeffiencts difference and empirical p-value for the first regressor in the model.

gap to add extra spacing between rows.

nodots suppress replication dots.

dec(#) to display # decimal places for all statistics. Defult is 3.

bdec(#) to display # decimal places for just the coefficient. Defult is 3.

pdec(#) to display # decimal places for just the empirical p-value. Defult is 3.

detail report the regression results for both groups.

(bdiffv) Reporting
noreport suppress bdiff test results.

(bdiffv) General Plotting
xshift(#) set the horizontal axis group offset to change the interval of the confidence interval. This value must be controlled between 0 and 0.5 (the default value is 0.1).

contour set whether to display significance levels at the same height.

(bdiffv) Advanced Plotting
1. Change the look of confidence intervals
cicolor() change the color of the confidence intervals. For details, refer to colorstyle.

cipattern() change the line pattern of the confidence intervals. For details, refer to linepatternstyle.

2. Change the look of scatter points
scacolor() change the color of the scatter points (coefficients). For details, refer to colorstyle.

scasize() change the size of the scatter points (coefficients). For details, refer to markersizestyle.

scasymbol() change the symbol of the scatter points (coefficients). For details, refer to symbolstyle.

3. Change the look of connection lines
linecolor() change the color of the connection lines. For details, refer to colorstyle.

linepattern() change the line pattern of the connection lines. For details, refer to linepatternstyle.

linewidth() change the width of the connection lines. For details, refer to linewidthstyle.

4. Change the look of significant labels
labcolor() change the color of the significant labels. For details, refer to colorstyle.

labposostion() change the size of the significant labels. For details, refer to clockposstyle.

labsize() change the symbol of the significant labels. For details, refer to textsizestyle.

5. Other options
* other options for the twoway command. For details, refer to twoway_options.

1. weights are not allowed in model().

2. If you do not specify any plotting options, the results of bdiffv will be identical to those of bdiff.

3. In the above options, if bdiff is displayed in parentheses, it means that the option is inherited from bdiff. If bdiffv is displayed, it means that the option is a new feature of this command.

Description

Introduction

Yujun, Lian (arlionn) released a package called bdiff on November 24, 2020, which can perform between-group difference analysis.

However, existing research can no longer simply be satisfied with displaying the differences between two sets of regression specific explanatory variables in digital form. Therefore, we urgently need a visual solution.

Based on the above background, I rewrote a visual solution based on the bdiff package and named it bdiffv. In addition to helping us perform intergroup difference tests after regression, this package can also display the differences graphically.

The Fisher's permutation test

The Fisher's permutation test can be used to test the significance of difference between two groups of any estimator.

In case of regression coefficients difference, Cleary (1999, pp.684-685) uses this method to determine whether there is a significant difference of "investment-cash flow sensitivity" coefficients between financial constraint (FC) firms and non-financial constraint (NFC) firms. Cleary states that: A bootstrapping procedure is used to calculate empirical p-values that estimate the likelihood of obtaining the observed differences in coefficient estimates if the true coefficients are, in fact, equal.

Step 1: Observations are pooled from the two groups whose coefficient estimates are to be compared. Using n1 and n2 to denote the number of observations available from each group, we end up with a total of n1 + n2 observations every year.

Step 2: Each simulation randomly selects n1 and n2 observations from the pooled distribution and assigns them to group 1 and group 2, respectively. Coefficient estimates are then determined for each group using these observations. The difference between coefficient estimates of group 1 and group 2 is denoted as (di)

Step 3: This procedure (Step 1 and Step 2) is repeated 5000 times.

The empirical p-value is the percentage of simulations where the difference between coefficient estimates (di) exceeds the actual observed difference in coefficient estimates (dSample).

This p-value tests against the one-tailed alternative hypothesis that the coefficient of one group is greater than that of the other group (H1: d > 0). For example, a p-value of 0.01 indicates that only 50 out of 5000 simulated outcomes exceeded the sample result, which implies the sample difference is significant, and supports the notion that d > 0.

Note that, the procedures in Cleary (1999, pp.684-685) is in fact a Fisher's permutation test, because Cleary do not use samping with replacement. So, the "A bootstrapping procedure" argument in Cleary (1999, pp.684) may be misleading. For details, see Efron and Tibshirani (1993, Section 15.2, pp.202).

For panel data

If the command used for Panel data is specified in model(string), e.g, xtreg, xtabond, etc., then the samping is clusted by id vairable specified by xtset.

SUR test

bdiff's surtest option provides a convenient way to perform test for "Do coefficients vary between groups? ". For details, see suest (example 2).

Visualisation solution

bdiffv provides a visualization solution for intergroup differences in bdiff. To achieve this, I mainly did the following:

step 1: Retain bdiff's method of calculating bwtween-group differences to avoid unnecessary errors.

step 2: Obtain the regression coefficients, confidence intervals, and p-values from the difference test provided by bdiff during the calculation process.

step 3: Use the rcap, scatter, and pcarrow commands to draw individual graphs. Some of the code was referenced from a solution provided by Asjad Naqvi.

step 4: Based on Professor Christopher F. Baum's suggestions for improving my modplot command, I have incorporated some of the features from modplot.

Examples

Basic usage code

`"sysuse auto.dta, clear"'

`"bdiffv, model(reg price rep78 headroom turn gear_ratio) group(foreign)"'

Note If your code runs successfully, you will get: 1. A group difference test table that is identical to the bdiff command; 2. A beautiful group difference test graph.

You can also click here to perform a secondary verification and see if the results match those of bdiff.

However, you should note that since seed(#) has not been set here for the time being, the p-value of the results will fluctuate to a certain extent.

Fully reproducible results of intergroup difference tests

`"sysuse auto.dta, clear"'

`"bdiffv, model(reg price rep78 headroom turn gear_ratio) group(foreign) seed(12138)"'

Note As long as seed(#) is set, the result will be reproducible.

However, you should note that, as with the bdiff command, changing the order of the data will cause the p-value of the difference test to fluctuate to a certain extent.

Do not report the results of the difference test table

`"sysuse auto.dta, clear"'

`"bdiffv, model(reg price rep78 headroom turn gear_ratio) group(foreign) seed(12138) noreport"'

Note In this case, the table showing the results of the difference test will not be reported, and only the image will be drawn. However, the progress bar will remain.

Bootstrap sample + permutation test

`"sysuse auto.dta, clear"'

`"bdiffv, model(reg price rep78 headroom turn gear_ratio) group(foreign) seed(12138) reps(100) bsample"'

Keep the significance markers at the same height

`"sysuse auto.dta, clear"'

`"bdiffv, model(reg price rep78 headroom turn gear_ratio) group(foreign) seed(12138) contour"'

Increase the distance between the two confidence intervals

`"sysuse auto.dta, clear"'

`"bdiffv, model(reg price rep78 headroom turn gear_ratio) group(foreign) seed(12138) xshift(0.3)"'

Advanced drawing options

It's fun to stay curious, and I hope my friends here will try out the advanced options settings for themselves.

Other situations where bdiff is applicable.

For other situations, such as SUR tests, Logit regression, and IV regression, please refer to the bdiff help file or click on the hyperlink (if installed).

Also see

Online: help for bdiff (if installed), chowtest (if installed), bsample, permute, suest.

Author

Basic information

Name: Shutter Zor (左祥太)

Affiliation: Accounting Department, Xiamen University.

E-mail: Shutter_Z@outlook.com

Other information

Blog: blog link

Bilibili: 拿铁一定要加冰

WeChat Official Account: OneStata

Other commands i have written

oneclick (if installed) ssc install oneclick (to install)

onetext (if installed) ssc install onetext (to install)

econsig (if installed) ssc install econsig (to install)

wordcloud (if installed) ssc install wordcloud (to install)

modplot (if installed) ssc install modplot (to install)

Acknowledgments

Thanks to Bilibili users (导导们). Thanks to Professor Christopher F. Baum for the
information that gave me a better understanding of Stata programming.

References

Cleary, S., 1999, The Relationship between Firm Investment and Financial Status,
Journal of Finance, 54(2): 673-692.
http://onlinelibrary.wiley.com/doi/10.1111/0022-1082.00121/full.

Efron, B., Tibshirani, R., 1993.
An Introduction to the Bootstrap, Chapmann & Hall.