# Iebaltab

**iebaltab** produces balance tables with multiple groups or treatment arms.

This article is means to describe use cases, work flow and the reasoning used when developing the commands. For instructions on how to use the command specifically in Stata and for a complete list of the options available, see the help files by typing `help iefolder`

in Stata. This command is a part of the package ietoolkit, to install all the commands in this package including this command, type `ssc install ietoolkit`

in Stata.

## Description

**iebaltab** is a command that generates balance tables (difference-in-means tables). The command tests for statistically significant difference between the categories defined in the grpvar(varname). The command can either test one control group against all other groups or test
all groups against each other. The command also allows for fixed effects, covariates and different types of variance estimators.

A lot of attention has also been spent on providing helpful error messages when the command is mis-specified. The command will also issue errors or warnings when the command is specified correctly but the nature of the data leaves potential for the results to be misinterpreted , or simply invalid. For example, if an observation has a missing value in a variable that is used in an F-test for joint significance, then Stata cannot do anything but drop that observation. This command will throw an error unless the user specifies the option that suppresses that error or if the user specifies any of the options that tells the command how to interpret missing values.

The command also attaches notes to the bottom of the table with infomration on, for example, which significance levels are used for stars, which fixed effects or covariates that were included (if any) etc.

The command estimates the descriptive stats, the t-test, and the F-tests using the following regressions:

### Group means and group standard errors

In the following regression, *balancevarname* refers to the variables (one at the time) listed in *balancevarlist*, *groupvar* refers to the variable listed in option **grpvar**(*varname*) and *groupcode* refers to the value corresponding to the group for which the means and standard errors are estimated for.

`reg balancevarname if groupvar = groupcode`

where _b[cons] from the returned results is the group mean and _se[cons] is the standard error in the group mean. Fixed effects and covaraiates are never included in this regression.

### t-tests

In the following t-test regression, *balancevarname* refers to the variables (one at the time) listed in *balancevarlist*. *testgroupdummy* is a dummy variable with the value 0 for one of the groups compared in this t-test and 1 for the other group. All other groups have missing values and are therefore excluded from the regression.

`reg balancevarname testgroupdummy`

`test testgroupdummy`

where r(p), from the returned results, is used when adding stars to the tables according to the thresholds specified in option starlevels().

### F-test

In the following F-test regression, *balancevarlist* refers to the list of all *balancevars* specified for the command. *testgroupdummy* is a dummy variable with the value 0 for one of the groups compared in this t-test and 1 for the other group. All other groups have missing values and are therefore
excluded from the regression.

`reg testgroupdummy balancevarlist`

`testparm balancevarlist`

where r(p), from the returned results, is used when adding stars to the tables according to the thresholds specified in option starlevels().

### Fixed effects

In the following t-test and F-test regressions with fixed effects, *fixed*
refers to the variable included as the fixed effects in option fixedeffects(). The p-values for the tests are obtained in the same way as described above.

`xi : reg balancevarname testgroupdummy i.fixed`

`test testgroupdummy`

`xi : reg testgroupdummy balancevarlist i.fixed`

`testparm balancevarlist`

### Covariates

In the following t-test and F-test regressions which include covariates, *covariatesvarlist* refers to the variables included as the control variables in option covariates(). The p-values for the tests are obtained in the same way as described above.

`reg balancevarname testgroupdummy covariatesvarlist `

`test testgroupdummy`

`reg testgroupdummy balancevarlist covariatesvarlist`

`testparm balancevarlist`

### Standard errors estimators}

In the following t-test and F-test regressions including the non-default
variance estimators, *vcetype* is the varaince estimator specfied.

`reg balancevarname testgroupdummy, vce(vcetype)`

`test testgroupdummy`

`reg testgroupdummy balancevarlist, vce(vcetype)`

`testparm balancevarlist`

### Combining them all

All options described above can be included in the same regression, for example:

```
xi : reg balancevarname testgroupdummy i.fixed covariatesvarlist, vce(vcetype)}
```

`test testgroupdummy `

## Examples

### Example 1

`iebaltab {it:outcome_variable}, grpvar({it:treatment_variable}) browse `

In the example above, let's assume that *treatment_variable* is a variable that is 0 for observations in the control group, and 1 for observations in the treatment group. Then in this example, the command will show the mean of {it:outcome_variable} and the standard error of that mean for the control group and the treatment group separately, and it will show the difference between the two groups and test if that difference is statistically significant.

### Example 2

```
global project_folder "C:\Users\project\baseline\results"}
```

`iebaltab `

*outcome_variable*, grpvar(*treatment_variable*) save("$project_folder\balancetable.xlsx")}

The only difference between example 1 and this example is that in this example the table is saved to file instead of being shown in the browser window.

### Example 3

`iebaltab `

*outcome1 outcome2 outcome3*, grpvar(*treatment_variable*) save("$project_folder\balancetable.xlsx") rowvarlabels rowlabels("outcome1 Outcome variable 1 @ outcome2 Second outcome variable")

Example 3 builds on example 2. There are now 3 variables listed as balance variables. In option *rowlabels()* two of those balance variables have been given a new label to be displayed as row title instead of the variable name. Instead of outcome1 the row title will be "Outcome variable 1", and instead of outcome2 the rowtitle will be "Second outcome variable". For balance variable outcome3 that is not included in *rowlabels()*, the command will use the variable label defined for outcome3 as row title since option *rowarlabels* was specified. If outcome3 does not have any row variable defined, then the variable name will be used as row title, just like the default.

## Back to Parent

This article is part of the topic Stata Coding Practices