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) egen pcsingle = mean(100 * (1 - married)), by(collgrad race) 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. Qui ttest price if foreign = 1, by(large_trunk)Įstadd local tdiff2 (`= round(`r(t)'. Qui estpost sum price_large_trunk price_small_trunk if foreign = 1 Qui ttest price if foreign = 0, by(large_trunk)Įstadd local diff2 `= round(r(mu_1) - r(mu_2). Qui estpost sum price_large_trunk price_small_trunk if foreign = 0
#Create table stata 12 code#
You need to modify your code as follows: sysuse auto, clear On a related note, I also wonder if I can suppress the summary statistics in the table header (I mean the mean/sd and b/t under the treatment names).
Ideally I would want to have the elements in the last row in columns one and two and discard all columns after column three. Mean/sd mean/sd b/t mean/sd b/t mean/sd b/tĪs you can see this is a 7x3 table. Mtitle("Domestic" "Foreign" "Difference") ///
Gen price_small_trunk = price if large_trunk = 0Įststo price_domestic: qui estpost sum price_large_trunk price_small_trunk if foreign = 0Įststo price_foreign: qui estpost sum price_large_trunk price_small_trunk if foreign = 1Įststo diff: qui estpost ttest price_large_trunk price_small_trunk, by(foreign)Įststo diff2: qui estpost ttest price if foreign = 0, by(large_trunk)Įststo diff3: qui estpost ttest price if foreign = 1, by(large_trunk)Įsttab price_domestic price_foreign diff diff2 diff3, ///Ĭells("mean(pattern(1 1 0) fmt(2)) b(star pattern(0 0 1) fmt(2))" "sd(pattern(1 1 0) par) t(pattern(0 0 1) par)") /// Gen price_large_trunk = price if large_trunk = 1 In particular, say you have 2x2 study design and want to display the mean and standard deviation of the outcome variable and add a further column that tests for the difference across treatment one and a further row that contains the difference and t-value across treatment two. I want to generate a table in Stata that contains means, differences and t-values for 4 different groups.