Difference between revisions of "Iebaltab"

Jump to: navigation, search
Line 1: Line 1:
<onlyinclude>
<code>iebaltab</code> is a Stata command that produces [[Balance tests | balance tables]], or difference-in-means tables, with multiple groups or treatment arms. It is a useful tool to use while [[Sampling & Power Calculations | sampling]], conducting [[Data Analysis | data analysis]] and [[Exporting Analysis | exporting results]] in a reproducible manner. This article describes how to use the command and how it works.  
'''iebaltab''' produces balance tables with multiple groups or treatment arms.


This article is meant 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 <code>help iefolder</code> in Stata. This command is a part of the package [[Stata_Coding_Practices#ietoolkit|ietoolkit]], to install all the commands in this package including this command, type <code>ssc install ietoolkit</code> in Stata.
==Read First==
</onlyinclude>
==Description==


'''iebaltab''' is a command that generates [[Balance tests|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
*<code>iebaltab</code> is a Stata command that produces [[Balance tests | balance tables]], or difference-in-means tables, with multiple groups or treatment arms.  
all groups against each other. The command also allows for fixed effects, covariates and different types of variance estimators.
*This command is a part of the package [[Stata_Coding_Practices#ietoolkit|ietoolkit]]. To install all the commands in this package including <code>iebaltab</code>, type <code>ssc install ietoolkit</code> in Stata.
* For detailed instructions on how to implement the command in Stata, type <code>help iebaltab</code> in Stata.


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.
==Overview==


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.
<code>iebaltab</code> is a Stata command that produces [[Balance tests | balance tables]], or difference-in-means tables, with multiple groups or treatment arms. The command can test for statistically significant differences of either one control group against all other groups or of all groups against each other. The command also allows for fixed effects, covariates and different types of variance estimators.  


The command estimates the descriptive stats, the t-test, and the F-tests using the following regressions:
<code>iebaltab</code> issues helpful error messages if the command is mis-specified or if the nature of the data leaves the potential for the results to be misinterpreted or invalid. For example, if an observation has a missing value in a variable used in an F-test for joint significance, then Stata cannot do anything but drop that observation. The command will issue an error unless the user specifies the option to suppress the error or specifies an option that tells the command how to interpret missing values.


=== Group means and group standard errors ===
The command attaches notes to the bottom of the table with information on, for example, which significance levels are used for stars, which fixed effects or covariates that were included (if any) etc.
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.


<code>reg balancevarname if groupvar = groupcode</code>
==Implementation==


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.
This section outlines the basic functionalities of the command -- estimating descriptive stats, t-tests, and F-tests – with sample code.  


===t-tests===
===Generating Descriptive Stats===
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.


<code>reg balancevarname testgroupdummy</code>
<nowiki>reg balancevarname if groupvar = groupcode</nowiki>


<code>test testgroupdummy</code>
where ''balancevarname'' refers to the variables (one at a time) listed in ''balancevarlist'', ''groupvar'' refers to the variable listed in the option '''grpvar'''(''varname''), and ''groupcode'' refers to the value corresponding to the group for which the means and standard errors are estimated. _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.


where r(p), from the returned results, is used when adding stars to the tables
===Running t-tests===
according to the thresholds specified in option starlevels().
 
<nowiki>reg balancevarname testgroupdummy
test testgroupdummy </nowiki>


===F-test===
where ''testgroupdummy'' is a dummy with the value - for one of the groups compared in the t-test and 1 for the other group. r(p), from the returned results, is used when adding stars to the tables according to the thresholds specified in option starlevels().
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.


<code>reg testgroupdummy balancevarlist</code>
===Running F-tests===


<code>testparm balancevarlist</code>
<nowiki>reg testgroupdummy balancevarlist
testparm balancevarlist</nowiki>


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


===Fixed effects===
===Including 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.
 
<code>xi : reg balancevarname testgroupdummy i.fixed</code>
 
<code>test testgroupdummy</code>


<code>xi : reg testgroupdummy balancevarlist i.fixed</code>
<nowiki>xi : reg balancevarname testgroupdummy i.fixed
test testgroupdummy
xi : reg testgroupdummy balancevarlist i.fixed
testparm balancevarlist </nowiki>


<code>testparm balancevarlist</code>
where ''fixed''refers to the variable included as the fixed effects in option fixedeffects().
===Including Covariates===


===Covariates===
<nowiki>reg balancevarname testgroupdummy covariatesvarlist
test testgroupdummy
reg testgroupdummy balancevarlist covariatesvarlist
testparm balancevarlist </nowiki>
where ''covariatesvarlist'' refers to the variables inlcuded as the control variables in option 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.
===Including Non-Default Variance Estimators===


<code>reg balancevarname testgroupdummy covariatesvarlist </code>
<nowiki>reg balancevarname testgroupdummy, vce(vcetype)
test testgroupdummy
reg testgroupdummy balancevarlist, vce(vcetype)
testparm balancevarlist</nowiki>


<code>test testgroupdummy</code>
where ''vcetype'' is the variance estimator specified.
 
===Combining Them All===
<code>reg testgroupdummy balancevarlist covariatesvarlist</code>
 
<code>testparm balancevarlist</code>
 
===Standard errors estimators===
 
In the following t-test and F-test regressions including the non-default
variance estimators, ''vcetype'' is the varaince estimator specfied.  
 
<code>reg balancevarname testgroupdummy, vce(vcetype)</code>
 
<code>test testgroupdummy</code>
 
<code>reg testgroupdummy balancevarlist, vce(vcetype)</code>
 
<code>testparm balancevarlist</code>
 
===Combining them all===


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


<code>xi : reg balancevarname testgroupdummy i.fixed covariatesvarlist, vce(vcetype)}
<nowiki>xi : reg balancevarname testgroupdummy i.fixed covariatesvarlist, vce(vcetype)}
 
test testgroupdummy </nowiki>
test testgroupdummy </code>


==Examples==
==Examples==
Line 93: Line 75:
===Example 1===
===Example 1===


<code>iebaltab {it:outcome_variable}, grpvar({it:treatment_variable}) browse </code>
<nowiki>ebaltab {it:outcome_variable}, grpvar({it:treatment_variable}) browse </nowiki>


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.
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.
Line 99: Line 81:
===Example 2===
===Example 2===


<code>global project_folder "C:\Users\project\baseline\results"}
<nowiki>global project_folder "C:\Users\project\baseline\results"}
 
iebaltab ''outcome_variable'', grpvar(''treatment_variable'') ///
iebaltab ''outcome_variable'', grpvar(''treatment_variable'') save("$project_folder\balancetable.xlsx")} </code>
save("$project_folder\balancetable.xlsx")} </nowiki>


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.
Here, the table is saved to file instead of being shown in the browser window as in Example 1.


===Example 3===
===Example 3===


<code>iebaltab ''outcome1 outcome2 outcome3'', grpvar(''treatment_variable'') save("$project_folder\balancetable.xlsx") rowvarlabels rowlabels("outcome1 Outcome variable 1 @ outcome2 Second outcome variable")</code>
<nowiki>iebaltab ''outcome1 outcome2 outcome3'', grpvar(''treatment_variable'') ///
save("$project_folder\balancetable.xlsx") ///
rowlabels("outcome1 Outcome variable 1 @ outcome2 Second outcome variable")</nowiki>


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.
Here, there are now three variables listed as balance variables. In option ''rowlabels()'', two of those balance variables are given a row label to use in lieu of the variable name. Instead of outcome1 and outcome2, the row titles will read "Outcome variable 1 and "Second outcome variable," respectively. Since outcome3 is not otherwise specified in ''rowlabels()'', the command will use outcome3’s variable name as the row title.


== Back to Parent ==
== Back to Parent ==
This article is part of the topic [[Stata Coding Practices]]
This article is part of the topic [[Stata Coding Practices]]
==Additional Resources==
[[Category: Stata]]

Revision as of 20:09, 3 June 2019

iebaltab is a Stata command that produces balance tables, or difference-in-means tables, with multiple groups or treatment arms. It is a useful tool to use while sampling, conducting data analysis and exporting results in a reproducible manner. This article describes how to use the command and how it works.

Read First

  • iebaltab is a Stata command that produces balance tables, or difference-in-means tables, with multiple groups or treatment arms.
  • This command is a part of the package ietoolkit. To install all the commands in this package including iebaltab, type ssc install ietoolkit in Stata.
  • For detailed instructions on how to implement the command in Stata, type help iebaltab in Stata.

Overview

iebaltab is a Stata command that produces balance tables, or difference-in-means tables, with multiple groups or treatment arms. The command can test for statistically significant differences of either one control group against all other groups or of all groups against each other. The command also allows for fixed effects, covariates and different types of variance estimators.

iebaltab issues helpful error messages if the command is mis-specified or if the nature of the data leaves the potential for the results to be misinterpreted or invalid. For example, if an observation has a missing value in a variable used in an F-test for joint significance, then Stata cannot do anything but drop that observation. The command will issue an error unless the user specifies the option to suppress the error or specifies an option that tells the command how to interpret missing values.

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

Implementation

This section outlines the basic functionalities of the command -- estimating descriptive stats, t-tests, and F-tests – with sample code.

Generating Descriptive Stats

reg balancevarname if groupvar = groupcode

where balancevarname refers to the variables (one at a time) listed in balancevarlist, groupvar refers to the variable listed in the option grpvar(varname), and groupcode refers to the value corresponding to the group for which the means and standard errors are estimated. _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.

Running t-tests

reg balancevarname testgroupdummy
test testgroupdummy 

where testgroupdummy is a dummy with the value - for one of the groups compared in the t-test and 1 for the other group. r(p), from the returned results, is used when adding stars to the tables according to the thresholds specified in option starlevels().

Running F-tests

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().

Including Fixed Effects

xi : reg balancevarname testgroupdummy i.fixed
test testgroupdummy
xi : reg testgroupdummy balancevarlist i.fixed
testparm balancevarlist 

where fixedrefers to the variable included as the fixed effects in option fixedeffects().

Including Covariates

reg balancevarname testgroupdummy covariatesvarlist
test testgroupdummy
reg testgroupdummy balancevarlist covariatesvarlist
testparm balancevarlist 

where covariatesvarlist refers to the variables inlcuded as the control variables in option covariates().

Including Non-Default Variance Estimators

reg balancevarname testgroupdummy, vce(vcetype)
test testgroupdummy
reg testgroupdummy balancevarlist, vce(vcetype)
testparm balancevarlist

where vcetype is the variance estimator specified.

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

ebaltab {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")} 

Here, the table is saved to file instead of being shown in the browser window as in Example 1.

Example 3

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

Here, there are now three variables listed as balance variables. In option rowlabels(), two of those balance variables are given a row label to use in lieu of the variable name. Instead of outcome1 and outcome2, the row titles will read "Outcome variable 1 and "Second outcome variable," respectively. Since outcome3 is not otherwise specified in rowlabels(), the command will use outcome3’s variable name as the row title.

Back to Parent

This article is part of the topic Stata Coding Practices

Additional Resources