*! version 2.9.0 22apr2014
help orth_out

Title

orth_out - automate and export summary stats/orthogonality tables

Syntax

orth_out varlist1
[using filename]
[if]
, by(varlist2) [options]

Output
replace overwrite existing file

vappend append table under the table in using

happend append table to the right of the table in using{

latex output with a latex table.

full output with full table.

dta output with a dta table.

sheet(textgrid) name the sheet in the workbook

sheetreplace replace the sheet specified in sheet().

Statistics
compare create columns for comparison between all treatment arms of varlist2

pcompare create columns for p-value of comparison between all treatment arms of varlist2

overall add a column for the overall mean

count add a row at the bottom specifying the number of people in each treatment arm of varlist2

proportion add a row at the bottom specifying the proportion of people in each treatment arm if varlist2

se include standard errors below the means, enclosed in parentheses

test run a joint orthogonality test on the treatment arms, and add a column with the p-value associated with it

vcount add a column for the overall N from the orthogonality test.

covariates(textgrid) include covariates in any regressions run (e.g. F-test, comparison, etc.)

interaction include interaction terms for all covariates.

reverse run a regression with the treatment variable as the dependent variable and produces a column with the coefficients and standard errors.

reverseall same as reverse, but with all balance variables together instead of separately.

vce(vcetype) add option for variance estimators from regress.

Table Formatting
bdec(#) specify the number of significant digits. The default is 3.

stars add stars of significance to the right of estimated coefficients

nolabel disable row and column labeling

armlabel(textgrid) specify column headings for the treatment arms

varlabel(textgrid) specify row headings for the balance variables

numlabel specify numeric headings for the treatment arms

colnum specify numeric headings for all columns below the column names

title(textgrid) specify a title for the table

notes(textgrid) add notes to the bottom of the table

Description

orth_out exports a table of means of specified balance variables, with the option to compare treatment arms and run an orthogonality test across the arms.
varlist1 is the list of balance variables to compare across, and varlist2 is the treatment arms.
varlist2 can be either one variable that indicates each treatment group, or individual binary indicators for each treatment.
The order of columns is immutable: it will always be means:overall:compare:reverse:reverseall:test:vcount.

Options

Output

replace permits overwriting the existing file.

vappend vertically appends the table generated to the one specified in using.
The master table will not appear in the output window, only in the excel sheet.

happend horizontally appends the table generated to the one specified in using.
The master table will not appear in the output window, only in the excel sheet.

latex exports a latex table in lieu of an excel one.
full needs to be specified in order for the table to be directly inputted to Tex via \input{} and the like.
Otherwise it will just give the statistics and row/column names without any table formatting, which depending on your objective may be better.

sheet(sheetname) adds a sheet to the existing file specified.
If the file does not exist, a new file will be created.
sheetreplace must be specified to replace a sheet with the same name in an existing workbook.

Statistics

compare adds columns to the right of the columns for the treatment arms.
These columns are the differences of the means of each variable of varlist1 across each treatment arm in varlist2.
Mutually exclusive with pcompare.

pcompare adds columns to the right of the columns for the treatment arms.
These columns are the p-values from a t-test of the differences of the means of each variable of varlist1 across each treatment arm in varlist2.
Mutually exclusive with compare.

overall adds a column to the right of the columns for the treatment arms with the overall mean.

count adds a row to the bottom of the table with the count of the number of observations in each treatment arm, with the label "N".

proportion adds a row to the bottom of the table with the proportion of the number of observations in each treatment arm, with the label "Proportion".

se adds standard errors enclosed by parentheses under the means.

test runs an F-test that the treatment arms do not predict the balance variable, giving the p-value for that test in the right-most column.
Note that in the special case where there is one treatment arm, for large enough n, the difference between an F-test and a t-test is negligible.

vcount adds a column with the combined observation count from the orthogonality test.

covariates(textgrid) includes specified covariates to add to regressions, such as the reverse test or the F-test.

interaction adds interaction terms between treatment for each of the covariates specified in covariates().

reverse adds a column of coefficients from a regression with each of the balance variables as independent variables and the treatment as the dependent variable.
Only an option when treatment is binary.
If treatment is not binary and reverse is specified, orth_out will assume that the first value is treatment, and everything else is control.

reverseall is the same as reverse, except instead of running each regression separately, all the balance variables are put into the regression together.

vce lets the user specify variance estimators for standard errors just like in regress. For more help, see regress and vcetype.

Table Formatting

bdec(#) specifies the number of decimal places
reported for all estimates. The default value for bdec is 3.

stars adds stars corresponding to levels of significance to the right of the coefficients that come from regressions/tests.
The star system follows the standard correspondence to alpha levels: *** = 0.01, ** = 0.05, * = 0.10.
Only visible in the saved excel file.

nolabel specifies that column and rows should not be labeled with variable labels, and instead will be left as the default "r#" or "c#".

armlabel(textgrid) specifies column headers for the treatment arms. Headers with spaces in them should be enclosed with double quotes.
If compare is specified, these will be automatically labeled with "(#) vs. (#)", where the #s correspond to the columns being compared.
If not specified, the default is that the columns are labeled with the variable or value labels, depending on how many variables are specified in the by().
If missing, the columns will simply be labeled with numbers.

varlabel(textgrid) specifies row headers for the demographic variables. Headers with spaces in them should be enclosed with double quotes.
If not specified, the default is that the rows are labeled with the variable labels (or if these are missing, variable names).

numlabel puts the column number in parentheses as the column header for each of the treatment arm columns (e.g. column 1 has a header of (1), etc.)

title(textgrid) specifies a title or titles above the regression table.
Note that if your title contains double quotes, you must enclose your title with compound double quotes.

notes(textgrid) specifies a note to be displayed below the orth_out table. Multiple lines of a note should be separated by commas.

Examples

Setup
. sysuse auto
(1978 Automobile Data)

Summary statistics
. orth_out price mpg, by(foreign) se

Domestic: Foreign:
_ _
Price:mean 6072.423 6384.682
se 429.491 558.994
Mileage (mpg):mean 19.827 24.773
se 0.658 1.410

Export table to Excel
. orth_out price mpg using test, by(foreign) se
file test.xls saved
Domestic: Foreign:
_ _
Price:mean 6072.423 6384.682
se 429.491 558.994
Mileage (mpg):mean 19.827 24.773
se 0.658 1.410

Orthogonality table testing if price and mpg are balanced between domestic and foreign cars (hint: they aren't)
. orth_out price mpg, by(foreign) se compare test count

Domestic: Foreign: (1) vs. (2): p-value f~y:
_ _ _ _
Price:mean 6072.423 6384.682 -312.259 0.680
se 429.491 558.994 754.449 .
Mileage (mpg):mean 19.827 24.773 -4.946 0.001
se 0.658 1.410 1.362 .
N:_ 52.000 22.000 74.000 .

Saved Results

orth_out saves the following in r():

Strings

r(title) table title

r(cnames) list of column titles

r(rnames) list of row titles

Matrices

r(matrix) table in matrix form

Author

Joe Long

jlong@u.northwestern.edu

Acknowledgments

Much thanks to Ellen Degnan for inspiration, Hideto Koizumi for contributions, and Matthew White for programming support.