
Ready? Let’s start.Įdit: Have a look at my follow-up post if you encounter any problems!Įdit 2: Another follow-up to improve the design. I explain three things: creating tables for 1.
#Create table stata 12 install
First install estout in Stata ( ssc install estout), then we can jump right into the examples. I think it is easiest to explain everything with examples, for which I use some tables from my current working paper. So hopefully this post is helpful for aspiring applied econometricians who want to automate output reporting from Stata into LaTeX. That has saved me a lot of time, but setting everything up took a long long time. you omit a particular group), you don’t have to change anything: the results get automatically updated in LaTeX. If you change something in your do-file (e.g. The advantage is that the whole system is dynamic. Note the extra trick of using a variable not shown explicitly to add separator lines.I use estout to generate tables of summary statistics and regression results that can be easily imported into LaTeX. groups collgrad race pcsingle pc, show(f) subvarname sepby(collgrad istotal)
#Create table stata 12 Pc
bysort collgrad race : gen pc = 100 * cond(istotal, total/alltotal, _N/total) * the table shows percents for college & race | collgrad and for collgrad | total

* for percents of the global total, we need to correct for doubling up egen pcsingle = mean(100 * (1 - married)), by(collgrad race) Here a concrete example for line-by-line study beats lengthy explanations. You may need to do some extra calculations, but nothing there amounts to rocket science: a smart high school student could figure it out. The clone of the original is relabelled as a Total category. Tip #4 To have a total category, temporarily double up the data. Groups has an option to save what is tabulated as a fresh dataset.

gen s_pcsingle = string(pcsingle, "%2.1f") So, strings just get shown by tabdisp as they come, which is what you want. The format() option of tabdisp does not reach into the string and change the contents it doesn't even know what the string variable contains or where it came from. format(%2.1f) and format(%3.2f) might do fine for most variables (and incidentally the important detail is the number of decimal places) but they would lead to a display of a count of 42 as 42.0 or 42.00, which would look pretty silly. I don't illustrate this fully, but I often use it when I want to combine a display of counts with numerical results with decimal places in tabdisp. Tip #3 Wire display formats into a variable by making a string equivalent. groups collgrad race pcsingle, subvarname sepby(collgrad) (In practice, these can be less constrained than variable names but often need to be shorter than variable labels.) We can use separators by calling up standard list options. We can set up better header text using characteristics. It's a wrapper for various kinds of tables, but using list as a display engine. groups can be installed from SSC (strictly, must be installed before you can use it). Tip #2 A user-written command groups offers different flexibility. tabdisp collgrad race, c(pcsingle) format(%2.1f) tabdisp lets you set a display format on the fly it does no harm and might be useful for other commands to assign one directly using format. It's billed as a programmer's command, but it is not difficult to use at all. I find that tabdisp is underrated by users. Once you have calculated it, you can (a) rely on the fact that it is constant within the groups you used to define it (b) tabulate it directly.

In this data set married is binary, so I won't show the complementary percent. Tip #1 You can calculate a percent variable for yourself. Let's use your example, which is excellent for the purpose. The upside is that all these tricks are easy to understand and often useful. The downside is that I don't know an easy way to get exactly what you ask. This answer will show a miscellany of tricks.
