help outreg2-------------------------------------------------------------------------------

Titles & related stuffs

outreg2-- Arrange regression, summary, and tabulation into an illustrative table seeout -- Opens a tab-delimited table in the data browser shellout -- Opens documents and their programs from inside Statalogout -- Converts log or ASCII files into various output formats mkest -- Convert variables to estimates matrix

Examples0. Basic game plan 1. Prefix and -bys:- 11. Marginal Effects 2. Running loops 12. Word or Excel files 3. Stored estimates 13. TeX files 4. Shorthand 14. Adding column titles or notes 5. Decimal places 15. n-way cross-tabulation 6. Sideway display 16. Group summary table 7. Summary tables 17. Fixed effects or legends 8. Drop/keep/order variables 18. Stats transformation/manipulation 9. Adding r( ) e( ) scalars 19. TBA 10. Odds ratios and rrr 20. Insert r-class cmd( ) outputs

Different versions of

outregandoutreg2

-------------------------------------------------------------------------------

Description

outreg2provides a fast and easy way to produce an illustrative table of regression outputs. The regression outputs are produced piecemeal and are difficult to compare without some type of rearrangement.outreg2automates this process by concatenating the successive regression ouputs in a vertical format. The resulting table is saved to the disk in ASCII format, which can be read by other programs.

outreg2thus facilitates the convertion of regression outputs to a standard format suitable for inclusion in a scholarly publication. The functionality of outreg2 is based on the earlier package outreg, by John Gallup. Unlikeoutreg,outreg2is capable of writing LaTeX-format tables, as well as ASCII, MS Word and MS Excel.

outreg2can report any regression output, provided it conforms totheusualconventionfor ereturn list. This includes most regression commands in Stata 7 or later.outreg2will report the latest regression output by default, or the list of stored estimates. The ancillary statistics from from stored return can also be accessed usinge()oraddstat().

outreg2will also report the usual statistics such as standard error with the asterisks for the levels of significance (1%, 5%, and 10%), t-statistics, p-values, the number of observations, R-squareds, and the number of groups in a panel estimation. Standarized beta coefficients, exponentially transformed coefficients (i.e. odds/risk ratios or hazard rate). The user can add their own column titles withctitleandaddnoteoptions.An immediate access to the produced table is provided in the browser view with

seeoption.outreg2also comes with automatically formatted number of significant digits, which avoids the awkward displays assoicated with the fixed format.

-------------------------------------------------------------------------------

SyntaxFull syntax:

outreg2[varlist][estlist]usingfilename[,options] [:command]Shorthand:

outreg2[varlist][estlist][,replace seeout] [:command]where

commandtakes one of estimation commands. The shorthand works only after a full syntax has been invoked.Note that

filenamemust be enclosed within double quotes if it contains embedded spaces.

Options+------+ ----+ Main +-------------------------------------------------------------

replacecreate a new file or overwrite the existing file.

seeoutdisplay the regression table in the browser.

labelreplace variable names with variable labels, also see stats(label)

label()takes the following options for label:

insert- insert labels next to variable namesproper- proper cases (capitalize the first letter)upper- all upper caseslower- all lower cases

sidewayspecify sideway display (with standard error next to coefficient). Useparen()ornoparento control the location of parentheses.

longinterweave the equation names into the same column with the variable names column, the default is usually wide. Also specifytextif you want a converted text as well.

onecolspecify one column to display multiple equations; the default is usually wide.

wideforces wide format with multiple columns, rarely required.

+--------------+ ----+ Output Files +-----------------------------------------------------

dtaproduces Stata file. A suffix "_dta" is added to the file name to prevent the possible loss of main data.

dta(saveold)produces in older Stata file format, as in saveold.

wordproduces rich text file (rft) compatible withMS Word. The file conversion can be specified at any time (you should do it with the last appedning). The existing file must not be open for it to be written over.

excelspecifies an xml, xls, xlm, or cvs file compatible with a standard spreadsheet likeMS Excel. Any existing file with the same name must be closed to have it replaced with a new file.

texproduces TeX output for a TeX typesetting program such as Scientific Word.

tex( )takes the following options for tex:

ment - a TeX fragment for inclusion in a documentfragetty - with some italics and varying font sizesprscape - horizontallyland

textproduces plain text file exactly.longorlabelwill sometimes cause the main output text file to be different from what might be expected. Use this option to obtain exactly specified text file.

quotespecifies quotation marks to encase each observation. See thenoquoteoption in outsheet for more details (all the output ofoutreg2comes from string variables).quotemay cause problems appending tables together.

commaspecifies that the ASCII file output be separated by commas rather than by tabs. This can cause problems if any of the user-defined text has commas in it (such as variable labels,ctitle,addstat, oraddnote). If that is the case, consider usingquoteas well.

+-------------------------------------------+ ----+ Statistics for each variable (main table) +------------------------

stats(stats)contains statistics to be reported per variable, the default isstats(coef se), space or comma separated, restricted to the estimation sample (single equation), will appear in the order specified by the user:coef se tstat pval ci ci_low ci_high beta N sum_w mean Var sd sum min max skewness kurtosis p1 p5 p10 p25 p50 p75 p90 p95 p99 range iqr cv semean median count corr covar pcorr semipcorr pcorrpval spearman tau_a tau_b

eqname varname aster label label_pr label_up label_low blank

str(

str) wherestris any string or numeric expression internally stored and recalled as string1, string2, etc.cmd(

macro:cmd) wheremacrois to be produced bycmdinternally stored and recalled as cmd1, cmd2, etc.

stnum(commands)applies Stata or user-defined commands tonumericalforms of thestats( ), use this option for mathematical/numeric operations, comma delimited, use quotes when there is a comma within a command, usually limited to stats specified instats( ), also seeststr( )below for string operations

ststr(commands)applies Stata or user-defined commands tostringforms of thestats( ), use this option to attach symbols or concatenate, comma delimited, use compound quotes if there is a comma in the command, usually limited to stats specified instats( ), also seestnum( )above

eformspecifies coefficients to be reported. This corresponds tooroption for logit, clogit, and glogit estimation,irrfor poisson estimation,rrrfor mlogit,hrfor cox and stcox hazard models, andeformfor xtgee. The default form of stcox is the hazard rate form; use theeformto report it.

level(integer)specifies the confidence level, in percent, for confidence intervals. The default islevel(95)or as set by set level, does not affect the significance levels of asterisks.

Short-cut for auxillary statistics

nosespecifies coefficients reported without std. errors

tstatdisplays t-statistics under the coefficent

pvaluedisplays p-values under the coefficent

cidisplays conf. intervals under the coefficent

betadisplays normalized beta coefficients (see the beta option of regress)

+--------------+ ----+ Significance +-----------------------------------------------------

alpha(numlist)specifies the levels of significance, separated by comma from the most significant to the least signficiant. Example:alpha(0.001,0.01,0.05). Up to 3 are automatically assigned asterisks. If more than 3 levels are defined, then the symbols must be specified withsymbol(text).

symbol(text)specifies symbols for the levels of significance from the most significant to the least significant, the defaultsymbol(***,**,*). The significance levels of 0.01, 0.05, and 0.10 will be automatically assigned in that order. If more than 3 symbols are assigned, then the same number of levels of significance must be specified usingalpha().

asterisk()specifies asterisks to be placed next to them; defaultstats(coef).

noasterno asterisks denoting statistical significance levels be reported.

2asterspecifies ** for 1% and * for 5%

10pctequivalent tosymbol(**,*,+)

+----------------------+ ----+ Decimals and Formats +---------------------------------------------

auto(integer)the number of automatically formatted decimals, the default isauto(3), i.e. three significant digits not counting the ones (i.e. the digit to the left of the decimal point). This means 1.234 and 0.123 might be displayed, while 12.345 or 0.1234 will be trimmed. A probable integer is reported without decimals. A very large or small number will be displayed in exponential format. Specifydec()orbdec()to disable it.

less(integer)specifies how many less significant digits to be displayed for the auxiliary (non-coefficient) statistics. The default isless(0), meaning no less.

decmark()contains the decimal marker; defaultdecmark(.)

fixed decimals & formats

dec(#)orfmt(type)for everything, defaultdec(3)andfmt(fc)where # is fixed decimals between 0 and 11, and

typeis one of the following:e exponential f fixed fc fixed with commas for thousands g general gc general with commas for thousands

Use the following only if you want them different from

dec(#)orfmt(ty> pe):

bdec(#)orbfmt(type)for coefficient onlysdec(#)orsfmt(type)for standard errortdec(#)ortfmt(type)for t-statisticspdec(#)orpfmt(type)for p-valuecdec(#)orcfmt(type)for conf. intervalrdec(#)orrfmt(type)for r-squareadec(#)orafmt(type)for addstat( ) contents+------------------+ ----+ Titles and notes +-------------------------------------------------

title(list)titles for your table; comma separated; use quotes for commas within a title. Titles can be added at any time. To erase your title, encase a space between quotes like this: title(" ")

ctitle(list)column titles; comma separated for each additonal row; semi-colon for each additional column; use quotes if comma is part of title. Example: ctitle("Wage, Participation","Wage: Participation"). To specify empty column title, specify ctitle(" ").

cttop(list)place additonal column titles on the top; comma separated, use quotes for multiple column titles.

addnote(list)add your own notes at the bottom. Must be specified in the firstoutreg2call when regression results are appended together. A blank line can be inserted by including "" as a note.

nonotesspecifies that notes and legends explaining the standard errors, asterisks, etc., not be included.

+--------------------------+ ----+ Parenthesis and brackets +-----------------------------------------

paren(stats)specifies parenthesis ( ) to be placed around the same list as stats( ).

noparenspecifies no parentheses be placed around standard errors, t-statistics, standard errors, etc.

bracketspecifies square brackets [ ] be used rather than parentheses ( ) around standard errors, t-statistics, etc.

bracket(stats)specifies square brackets [ ] to be placed around the same list as stats( ).

+--------------------------------------------+ ----+ Statistics for each regression (at bottom) +-----------------------

e(scalars)reports e-class scalars at the bottom of the table. They may be requested individually, as ine(N ll r2), or for all, by specifyinge(all). The reported e-class statistics are automatically formated by auto-digits, unlessadechas been specified for it.

addstat(name,stats,..)access e-class, r-class, s-class scalar statistics, or just plain numbers in new rows below the R-squared (if shown). Comma separted. The user must specify both a name and a value for the statistic. See example.

addtext(name,text,..)specifies user-added text (including numbers) to be displayed in new lines below the R-squared (if shown). Unlikeaddstat,addtextwill not format numbers nor try to interpret any e-class text (such as e(N) or e(title)).

adjr2specifies that the adjusted R-squared be reported rather than the regular R-squared when available.

noconsspecifies that the intercept (constant) be not reported.

nonispecifies that the number of groups in a panel data regression not be reported (e.g. the number of groups specified by the i( ) variable in xtreg).

nor2specifies that no R-squared (or adjusted R-squared) be reported.

noobsspecifies no number of observations is to be reported.

+-------------------------+ ----+ Equations and Variables +------------------------------------------

drop(varlist)Drop these variables. Do not include the dependent variable in this list.

keep(varlist)Keep and report these variables.

eqdrop(eqlist)Drop these equations from the table

eqkeep(eqlist)Keep and report these equations.

sortvar(varlist)Sort and order variables; non-existent variable names are ignored.

groupvar(names)Sort and order variable; non-existent names are inserted as super-rows or row-heading.

+------------------+ ----+ Marginal effects +-------------------------------------------------

mfxreports marginal effects as computed by mfx. It will reported marginal effects instead of estiamted coefficients.

margin(u|c|p)the unconditional, conditional, and probability marginal effects for truncreg, marginal from STB 52, or dtobit from STB 56. One of u, c, or p is required after dtobit, corresponding to the unconditional, conditional, and probability marginal effects, respectively. It is not necessary to specifymarginafter dprobit, dlogit2, dprobit2, or dmlogit2.

+--------------------+ ----+ Summary Statistics +-----------------------------------------------

sumsummary be reported after a regression command, restricted to the estimation sample, i.e. e(sample)==1, unless no regress exists orrawoption specified. This is the same asstats(mean sd).

rawdo not restrict the sample to e(sample) or perform casewise dropping. Currently works only with sum. The number of observation reported is the maximum.

sum(log)summary table just like the one from log file. Default is raw (no casewise dropping). Use eqdrop( ) or eqkeep( ) to get what you want.

sum(detail)detailed summary table. Default is raw (no casewise dropping). Use eqdrop( ) or eqkeep( ) to get what you want.

+-------------+ ----+ Tabulations +------------------------------------------------------

crosstabn-way cross-tabulation. Varlist is required. The first variable must be counting numbers, i.e. 0, 1, 2, etc., and the rest must be non-strings. See example below.

+--------------------------------+ ----+ Laptop/External/Network Drives +-----------------------------------

slow(#)specifies # of milli-second delay. Specify slow(100) or larger if you are getting "could not be openend r(603)" error; it's probably either (1) your storage device is running too slow, or (2) you don't have write-access, in which case you need to change working directory with cd.

-------------------------------------------------------------------------------

Example 0. Basic game plan

You should specify the current directory where all the files will be stored. Alternatively, you can specify the complete pathway from within

outreg2, but you must encase it with quotations marks.cd c:\ sysuse auto,clear regress mpg foreign weight headroom trunk length turn displacement outreg2 using myfile, replace cttop(full) regress mpg foreign weight headroom outreg2 using myfile, see word excel tex dta

You can immedicately see the changes. The variable "weight" loses some of its significance in the full specification. The estimated effect of weight can be shown to be downward-biased from -0.00420 to -0.00647 by omitting a number of covariates. This is an easy way to check for collinearity and misspecification.

You can use

e( )oraddstat( )option to augment the standard regression results with other e-class statistics (scalar only).addstatcan handle r-class and s-class results as well, if they exist. The following codes are equivalent excpet in appearance.outreg2 using myfile, e(r2 ll) outreg2 using myfile, addstat(R-squared by hand, e(r2), Log Lik, e(ll))

If you want to see everything available in the e-class, do it like this:

outreg2 using myfile, e(all)

Example 1. Prefix and -bys:-

outreg2can be used in as a prefix.sysuse auto, clear outreg2 using myfile, replace ti(Car stuff): reg price mpg weight turn outreg2 using myfile, see excel: reg price mpg weight turn if price > 6100

It is also byable with -bys:- prefix.

bys foreign: outreg2 using myfile, side replace see: reg rep78 head weight gear length turn [aw=mpg]

Example 2. Running loops

Because this involves a loop, you must copy and paste into a do-file:

sysuse auto,clear cap erase myfile.txt forval num=1/5 { regress mpg weight headroom if rep78==`num' outreg2 using myfile } seeout

Alternatively, make use of macro

local replace replace forval num=1/5 { regress mpg weight headroom if rep78==`num' outreg2 using myfile, `replace' local replace }

Example 3. Stored estimates

You can automatically recall the stored estimates by specifying them from within

outreg2. To distinguish them from the varlist, place the estlist within a pair of[square brackets].sysuse auto,clear regress mpg foreign weight headroom trunk length turn displacement

est store Full regress mpg foreign weight headroom

est store Restricted1 regress mpg foreign weight

est store Restricted2 outreg2 [Full Restricted1 Restricted2] using myfile, replace see

outreg2will take the stored estimates as wildcards (*). Try this:outreg2 [*] using myfile, see replace outreg2 [R*] using myfile, see replace

The varlist may be combined with the estlist. The varlist will take the wildcards as well, provided they exist in the estlist.

outreg2 foreign weight [*] using myfile, see replace

If you are specifying the varlist, you must make certain the desired varlist exists in all the stored estiamtes. Since not all equations may contain the specified varlist, it is usually a poor idea to combine the one column option with the varlist.

Example 4. Shorthand

outreg2will remeber the last set of options you specified until the end of the day. The stored command will expire at mid-night to prevent the possible loss of finished table by inadvertantly writing over a finished file. The following shorthand should be tried separately.outreg2 outreg2, replace outreg2, seeout

The following two options are excluded from the stored command: seeout and replace. These two must be specified each time you invoke

outreg2through the shorthand. To change the stored options, you must invoke the full syntax with the specified using file (i.e. outreg2 using myfile, etc). The varlist and the stored estimates names are not stored with the command.For someone who is in a hurry,

outreg2will take the following syntax, provided the desired options have been stored by invoking them in the full syntax. The varlist and/or the estlist are still allowed under this syntax. This pre-command syntax is made available for the benefit of iterative users.outreg2 : reg mpg foreign weight headroom outreg2, replace : reg mpg foreign weight headroom outreg2 seeout

Example 5. Decimal places

By default the regression coefficients are shown with auto-digits, but a user may wish to specify their own number of decimals places. We could use the option dec(5) to display 5 decimal places for all statistics or bdec(5) for just the coefficient, sdec(5) just for standard error, etc.

outreg2 using myfile, replace auto(4) outreg2 using myfile, dec(5) outreg2 using myfile, bdec(5) bfmt(f) sdec(7) sfmt(e) see

Example 6. Sideway displayMedical journals often requires the displays to go sideways. Use

sidewayto make this happen.sidewayis compatible withstats().outreg2 using myfile, sideway stats(coef aster se) noparen dec(3) replace

Note the above code is equivalent to building the table one column at a time like this:

outreg2 using myfile, stats(coef) replace noparen dec(3) outreg2 using myfile, stats(aster) noparen dec(3) outreg2 using myfile, stats(se) noparen dec(3)

Some journals often prefer t-statistics to standard errors and don't use asterisks to denote statistical significance. Some people use brackets. The title( ) option requires quotation marks when it contains a comma. Note that

decdecimal option apply to both the coefficients and the standard errors.regress mpg foreign weight outreg2 using myfile, tstat bracket noaster title("No standard errors!") seeout

Example 7. Summary tablesUse

sumto place summary statistics into a table. The sample mean and the standard deviation for the sample used in the earlier regression will be automatically displayed.* After estimation sysuse auto, clear reg mpg price rep weight length outreg2 using myfile, sum replace outreg2 using myfile, see

* Regular summary table * note: version 11 and above requires clear* to prevent mismatch between e(b) and e(sample) clear* sysuse auto, clear outreg2 using myfile, sum(log) replace eqdrop(N mean) see outreg2 using myfile, sum(detail) replace eqkeep(N max min) see outreg2 using myfile, sum(detail) replace see

Example 8. Drop/keep/order variables

Specifying a varlist can be convenient to limit the output table to only the essential coefficients. For example, we may want to control for the influence of dummy variables, but not report their estimated coefficients.

sysuse auto, clear tab rep78, gen(repair) regress mpg foreign weight repair1-repair4 outreg2 weight foreign using myfile, drop(repair*)

Alternatively,

keep()anddrop()can be used to control the displayed variables. Usenoconsto drop constants.outreg2 using myfile, drop(repair*) replace outreg2 using myfile, keep(mpg foreign) outreg2 using myfile, nocons seeout

There are several ways to order variables in the output. The first is to order them when running regression. The second way is to specify varlist from within

outreg2. Or you might trysortvar()orgroupvar().* single equation reg mpg rep78 head trunk weight outreg2 using myfile, replace sortvar(trunk turn) reg mpg rep78 head weight turn disp gear outreg2 using myfile, sortvar(trunk turn) see

* multiple equations reg3 (mpg rep78 head trunk weight) (head trunk weight rep78 gear) outreg2 using myfile, replace long reg3 (mpg rep78 head weight turn disp ) (mpg rep78 head trunk weight gear) outreg2 using myfile, sortvar(trunk turn) see long

* groupvar( ) will create super-rows reg mpg rep78 head trunk weight outreg2 using myfile, replace reg mpg rep78 head weight turn disp gear outreg2 using myfile, groupvar(Group1 trunk turn head weight Group2) see

Example 9. Adding r( ) e( ) scalars

Additional statistics may be added with

addstat()oraddtext(). Values stored in macros r( ), e( ), or s( ) can be included directly. You can see what values are available by typingereturn listorreturn list.To test the equality of two of the estimated coefficients and report the results in the table, note that

testwill sometimes return chi-squared, then you would instead useaddstat(chi-square test,r(chi2)):reg mpg foreign weight length test foreign length outreg2 using myfile, adds(F-test, r(F), Prob > F, `r(p)') replace seeout

To add results of lincom postestimation command to a table:

sysuse auto, clear reg price mpg rep78 head lincom mpg + rep local tstat=r(estimate)/r(se) local pval = tprob(r(df), abs(`tstat')) outreg2 using "myfile", adds(joint, r(estimate), t-stat, `tstat', p-val,`pval') replace see

In some cases it is better to save the value of a previously calculated statistic in a local macro and then put that into

addstat():regress mpg rep78 headroom test rep78 local F1 = r(F) test headroom outreg2 using 2test, addstat(Test1 F, `F1', Test2 F, `r(F)')

If it is missing,

outreg2will automatically calculate e(p), which is presumably the F-test or chi-square-test of significance of a regression.outreg2 using myfile, addstat(F test, e(p))

Another example would be to report a pseudo R-squared after a logit estimation, which

outreg2does not otherwise report.logit foreign price trunk weight outreg2 using myfile, addstat(Pseudo R-squared, `e(r2_p)')

Example 10. Odds ratios and exponentials

Odds ratios are exponential transformations of coefficients. As noted above, there is no way of knowing after an estimation command if the user chose to report the exponentiated form of coefficients. The user must choose the

eformoption inoutreg2to get the same form of the coefficients displayed by the estimation into theoutreg2table.For duration models, the exponential form is known as the hazard ratio. For other models it is known as odds ratio, relative risk ratio, or incidence rate ratio.

sysuse auto,clear logit foreign price mpg rep78, or outreg2 using myfile, replace cti(raw) outreg2 using myfile, eform cti(odds ratio) see

* Alternatively: outreg2 using myfile, stnum(replace coef=exp(coef), replace se=coef*se) cti(odds ratio) see

Note that coef was first transformed, then used to calculate se in the example above.

Example 11. Marginal Effects

mfxoption can be used to report marginal effects after mfx command has been applied. sysuse auto, clear logit foreign mpg rep78 head mfx compute outreg2 using myfile, replace outreg2 using myfile, mfx ctitle(mfx) see

marginswill report it as well. sysuse auto, clear logit foreign mpg rep78 head margins, dydx(_all) post outreg2 using myfile, ctitle(margins) seeFor multiple outcomes, you may want to use

mfx2by Ricahrd Williams or margeff by Tamas Bartus. They are both available from ssc.

margeffexample: sysuse auto, clear mlogit rep turn mpg price margeff, at(mean) replace outreg2 using myfile, cttop(margeff) see replace

mfx2runs a little slower: sysuse auto, clear mlogit rep turn mpg price mfx2, replace outreg2 using myfile, long cttop(mfx2) see replaceThe marginal effects reported by dprobit, dlogit2, dprobit2, and dmlogit2 are automatically reported by

outreg2.Because truncreg, marginal, and dtobit report both regression coefficients and marginal effects, the user must specify the

marginoption foroutreg2report the marginal effects.dtobit, on the other hand, calculates three different marginal effects. The user must specify which marginal effect, the unconditional, conditional, or the probability uncensored, to be reported. Note that "version 6" must be set for

dtobitto work.version 6: tobit mpg trunk weight, ll(17) version 6: dtobit outreg2 using myfile, margin(u) ctitle(Unconditional) nor2 replace outreg2 using myfile, margin(c) ctitle(Conditional) nor2 outreg2 using myfile, margin(p) ctitle(Probability) nor2 see

Example 12. Word or Excel filesUse

wordorexcelfor automatic generation of Word/Excel files:reg price mpg rep78 headroom trunk weight outreg2 using myfile, word excel replace

Follow these directions for manual conversions from .txt files:

In

MS Word, open or insert the file created byoutreg2. Select the estimation text that is in columns (not the notes at the bottom of the table or the title at the top, if any), and choose Table, Convert Text to Table.To shift the table within

MS Word, highlight the entire table, choose Table Properties (go the top menu, drag down on the Table option), and then click the alignment as Left instead of Center.In

Excel, open the file created byoutreg2and follow the default choices in the Text Import Wizard (if you do not see the file, choose All Files as the File Type). Prevent the conversion of the parenthesis into a negative number (an accounting convention) by doing the following: 1. import it as "Delimited", 2. choose Tab as the Delimiters, and 3. Choose "Text" as Column data format after Highlighting all the columns by shift-down, right-clicking.To export the .xml table to a word processor, you should separately copy the table and the notes at the bottom of the table (prevents the notes from taking up too much space). You can avoid this problem by opening the .txt file manually from inside

MS Excel, as detailed earlier, or copy and paste the notes into another cells inMS Excel, which will cause them to be displayed properly.To get rid of "green tabs" in Excel: From inisde Excel, Tools > Options > Error Checking. When you get there, uncheck "Number stored as text". No more green triangles.

You can also use Stat/Transfer if you have one. Choose ASCII-Delimited as the input file and choose

Excelas the output file. You will need to adjust the column widths from insideExcel.

Example 13. TeX files

LaTeXcompatible table can be created withtexoption. With the use of free conversion software, such as MiKTeX, you can create Adobe PDF files of the finished tables directly within Stata by invoking a shell command.regress mpg foreign weight outreg2 using myfile, tex replace

Free TeX-to-PDF conversion software are available, such as the MiKTeX (www.miktek.org) for Windows or teTeX (www.tug.org/teTeX/) for Unix/Linux. They can be invoked with a shell command:

!texify -p -c -b --run-viewer myfile.tex {using MiKTeX on Windows) !pdflatex myfile (using teTeX on Linux)

outreg2cannot append TeX format tables to one another, so regressions must be appended in ASCII form until the last regression, which is appended with thetexoption.{_end}The base font point size of tex in a TeX table can be specified with the

tex()parameter. TeX only allows font sizes of 10 and 11 points besides the default of 12 point. Thetexfragoption creates a TeX fragment for inclusion in a larger TeX document. For example, a TeX fragment table from the first regression above could be created withoutreg2 using myfile, tex(frag)

and then be included in the following TeX document with the \input{myfile} command:

\documentclass[10pt]{article} \begin{document} ... text before inclusion of table myfile.tex ... \input{myfile} ... text after inclusion of table myfile.tex ... \end{document}

Technical Note: Non-alphanumeric characters often have special meaning in TeX, namely _, %, #, $, &, ~, ^^, \, {, }. To print them like any other character, include a \ in front of the character.

outreg2automatically does this for the first two, _ and %. You can include the other characters in titles, variable labels, or notes if you preceed them with with a \ in the Stata text. The exception is \ itself; \ must be replaced with $\backslash$ to render properly in TeX.In addition, in TeX the characters <, >, and | will only appear as themselves in math mode, so they must be written as $<$, $>$, and $|$.

TeX codes can be inserted into

outeg2titles, variable labels, and added notes. This requires understanding TeX formatting codes. The example below creates a Greek letter chi with a squared exponent for a chi-squared test statistic.outreg2 using myfile, addstat($\chi^2$, 22.1) tex

Note that outreg2 will automatically convert < or > but not chi^2.

outreg2 using myfile, addstat(LR $\chi^2$, e(chi2), Prob < $\chi^2$, e(p)) tex

outreg2automatically converts _ to \_, except when it finds two $'s in the text, in which case it assumes the _ is a subscript designator in a TeX inline equation. That means that if you want to add text that includes an inline equation, but you really want the _ to appear as such in the TeX table, you must replace it with a \_.Stata will interpret $ immediately followed by a letter as a global macro. To get Stata to output a literal $, insert an escape character "\" like this: \$. R-squared, for example, must be "\$R^2$" rather than "$R^2$" because $R would be evaluated as the value of global macro R.

Putting a literal "$" in TeX output can be confusing: to get "$US" in the TeX output, for example, one needs "\$US" in the TeX input file, which requires "\\\$US" in Stata text, because Stata resolves "\\" into "\" and "\$" into "$".

A final quirk: you cannot use the results of the Stata macro $S_FN in

outreg2text for a TeX table if you use Microsoft Windows. $S_FN returns the path name for the current data file which in Windows includes \ characters which will prevent the TeX table from rendering properly.

Example 14. Adding column titles or notes

You can add a column title "Base case (mpg)" to distinguish this regression from a second regression. No quotation marks are required around the column title because it does not contain commas. Use

cttop()to add additional column title to the default column titles.outreg2 using myfile, replace ctitle(Base case (mpg)) outreg2 using myfile, cttop(On top)

You can add explanatory note at the bottom of a column using the

addnoteoption. Note that since the text inaddnotedoes not contain parentheses or commas it does not need quotation marks.outreg2 using myfile, addnote(Dummy variables not shown)

addnotefor inserting a blank line, followed by the time the program was run (from the built-in Stata functions $S_TIME and $S_DATE), and the dataset used by the estimation (from the Stata function $S_FN).regress mpg foreign weight length outreg2 using myfile, addn("", "Time $S_TIME, $S_DATE", Data from $S_FN) replace

Example 15. n-way cross-tabulationn-way tabulation likes of which are also produced by tab3way or table. It will take about a minute to run.

* Prepare data sysuse auto, clear egen mileage=cut(mpg), group(10) egen paid=cut(price), group(3) egen heavy=cut(weight), group(3)

* 3-way cross-tabulation sideway outreg2 mileage paid heavy using myfile, see replace cross side

* 5-way cross-tabulation without percentage outreg2 mileage paid foreign rep78 heavy using myfile, see replace cross stats(coef)

Example 16. Group summary tablesysuse auto, clear gen white=cond(uniform( )>.5,1,0) gen black=cond(white==1,0,1) gen male=cond(uniform( )>.5,1,0) gen female=cond(male==1,0,1)

* do it with -bys:- bys male black: outreg2 using myfile, sum(log) eqkeep(mean N) drop(white female male black) excel replace

* do it by hand outreg2 using myfile if white==1 & male==1, sum(log) eqkeep(mean N) cttop(white, male) drop(white male female) excel replace outreg2 using myfile if white==1 & female==1, sum(log) eqkeep(mean N) cttop( , female) drop(white male female) excel outreg2 using myfile if white==1, sum(log) eqkeep(mean N) cttop( , total) drop(white male female) excel outreg2 using myfile if black==1 & male==1, sum(log) eqkeep(mean N) cttop(black, male) drop(white male female) excel outreg2 using myfile if black==1 & female==1, sum(log) eqkeep(mean N) cttop( , female) drop(white male female) excel outreg2 using myfile if black==1, sum(log) eqkeep(mean N) cttop( , total) drop(white male female) excel

Example 17. Fixed effects or legendsTwo-way fixed-effects estimation with dummy indicators:

* set up data sysuse auto, clear ren rep78 state ren turn id keep id price mpg weight state tab state, gen(ST)

* regress and report xtreg price mpg weight ST*, fe i(id) outreg2 using myfile, replace drop(ST*) addtext(State FE, YES, Year FE, YES) xtreg price mpg weight ST*, fe i(id) outreg2 using myfile, drop(ST*) addtext(State FE, NO, Year FE, YES) reg price mpg weight ST* outreg2 using myfile, drop(ST*) addtext(State FE, NO, Year FE, NO)

* legend outreg2 using myfile, st(str(Coef) str(Stn Err) str(Spearman)) noparen ct(Legend) replace outreg2 using myfile, st(coef se spearman blank)

Example 18. Stats transformation/manipulationThe contents of

stats( )can be manipuated with standard Stata commands.Use

stnum()to work withnumericalforms.* multiply by 100 sysuse auto, clear reg mpg price weight outreg2 using myfile, replace outreg2 using myfile, stats(coef se) stnum(replace coef=coef*100, replace se=se*100)

* exponentiate both coef and se outreg2 using myfile, stats(coef se) stnum(replace coef=exp(coef), replace se=coef*se)

* absolute value of t-statistics outreg2 using myfile, stats(coef tstat) stnum(replace tstat=abs(tstat))

Use

ststr()to applystringoperations.* add dollar-sign ($) for the mean of price reg mpg price weight outreg2 using myfile, stats(mean) ststr(replace mean="$"+mean if varname=="price") replace

* add "max" to maximum and "min" to minimum outreg2 using myfile, stats(max min) ststr(replace max="max "+max if max~="", replace min="min "+min if min~="")

Use

stnum()andststr()together.* multiply by 100 and add percent (%) sign outreg2 using myfile, stats(mean) stnum(replace mean=mean*100) ststr(replace mean=mean+" %" if mean~="")

* You can automate this process by writing your own programs and inserting them like this:

prog drop _all prog define percent replace mean=mean*100 end

prog define symbol replace mean=mean+" %" if mean~="" end

outreg2 using myfile, stats(mean) stnum(percent) ststr(symbol)

* To manipuate string based on numerical content, generate a numerical copy in stnum( ): outreg2 using myfile, stats(mean) stnum(gen temp=mean) ststr(replace mean="Positive" if temp>0)

* To concatenate (currently works only with major statistics, i.e. coef, se, tstat, etc.: outreg2 using myfile, stats(coef) ststr(replace coef=coef+" "+se) noaster

Example 20. Insert r-class cmd( ) outputsYou can insert output from r-class command in the table body through cmd( : ) sub-option. Indep and dependent variables will be fed to them.

* outputs Kendall's tau-a and tau-b sysuse auto, clear reg rep78 headroom length turn gear_ratio outreg2 using myfile, replace stats(corr, spearman, cmd(r(tau_a): ktau), /* */cmd(r(tau_b): ktau))

* double-check ktau rep78 headroom ret list

Write and insert your own r-class outputYou can write your own r-class program and insert their outputs. A scalar should be returned on two inputs: independent variable and dependent variable. It needs to accept [if] syntax. c_local programs will work, too, but there might be a conflict.

* r-class program that calculates coefficient of variation cap prog drop coefvar prog define coefvar, rclass syntax varlist(max=2) [if] gettoken dep indep : varlist qui sum `indep' `if' local variation=`r(sd)'/`r(mean)'*100 ret scalar variation=`variation' end

* test your r-class program sysuse auto, clear reg rep78 headroom length turn gear_ratio coefvar rep78 headroom if e(sample) ret list

* run them sysuse auto, clear reg rep78 headroom length turn gear_ratio outreg2 using myfile, replace stats(coef, se, sd, cmd(r(variation): coefvar))

* return c_local instead of r-class scalar cap prog drop coefvar2 prog define coefvar2 syntax varlist(max=2) [if], [proportion] gettoken dep indep : varlist qui sum `indep' `if' local hundred 100 if "`proportion'"=="proportion" { local hundred 1 } local variation=`r(sd)'/`r(mean)'*`hundred' c_local variation=`variation' end

* run them sysuse auto, clear reg rep78 headroom length turn gear_ratio outreg2 using myfile, stats(coef, se, sd, cmd(variation: coefvar2, proportion))

Send one to the e-mail address belowPrograms like these can made into a sub-option for inclusion the future versions. Please note that it should be something of interest to other people.

-------------------------------------------------------------------------------

Different versions ofoutregandoutreg2

outreg2will work under different versions of Stata:Stata 11.0:

seeoutwill require an additional keyboard hit before moving on Stata 8.2: full functionality Stata 8.0: reported stored estimates will be left behind when they are specified Stata 7.0: no stored estimated no colon character ":" in your file path; use -cd- instead Shorthand syntax for outreg2 or seeout will not work in versions earlier than 8.0. tfmt(.), rfmt(.), pft(.), afmt(.) do not work cmd( ) and str( ) do not work; stnum( ) or ststr( )? Other limitations may exit exist; best not to try anything complicatedCompared to the original

outreg,outreg2implements the following as the default:append,3aster,coefastr,se, andnolabel.2asterandtstatprovide the access to the old default options.sigsymbis replaced withsymbol.xstatsis not supported.The auxiliary statistics (standard error, etc) are no longer reported in absolute values. The levels of significance are strictly less than the values (used to be less than or equal to). bdec and bfmt no longer take multiple inputs.

The embedded spaces in the folder names are now accepted.

title(list)can be added anytime. The .out extension is phased out in favor of .txt extension. A new file will be created if it did not exist. The past restrictions on the number and the size of variable names have been generally expanded to the system limit.The newly available features are the access to

label,e(ereturnscalars), automatically formatted digits byauto(integer)andless(integer),alpha(numlist)provides user-defined test of hypothesis,seeoutcalls up the pop up table in the data browser view, the choice of equation names as wide orlong, the converted tables inword,excel, andtexwith theshelloutcommands for them placed on the screen.The

[estlist], which is a list of stored estimates, is accepted with or without wildcard abbreviations. The shorthand syntax with a limited option can now be implemented as an independent command following a regression command, or as a pre-command preceeding it.The

seeoutshell is also placed on the screen. Theseeoutcommand will work only afteroutreg2. A majority of options should work with 8.2. The shell commands were designed with a Windows XP/NT. They will not work on non-Windows platforms.

How to report a possible error1. it's best if you send an example using -sysuse- or -webuse- data 2. create a trace log file containing the error 3. Send them to whoever wrote the thing and ask nicely.

cap log close log using mylog.txt, text replace which outreg2 /* or whatever command you are dealing with * > / cret list sysuse auto, clear /* or whatever data you are using */ reg rep78 trunk turn foreign /* or whatever you are doing */ set trace on outreg2 using myfile, replace /* or whatever that gets you the error */ log close

Acknowledgementscodes from pcorr2 by Richard Williams have been incorporated for stats( ) suboption.

AuthorRoy Wada roywada@hotmail.com

based on the earlier works by John Luke Gallup john_gallup@alum.swarthmore.edu

Thanks to Kit Baum for advice and providing access to John's later works. I also thank those who have reported errors, making it possible to fix them in timely fashion.

Also seeSTB: sg97 (STB-46, STB-49, STB-58) Manual:

[U] Estimation and post-estimation commands[U] Overview of model estimation[R] Estimation commandsOnline: est, postfile, outfile, outsheet, save, modltbl, desrep