Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: combining tables |

Date |
Tue, 30 Oct 2012 22:37:29 +0000 |

The short answer seems to me to be that most of the activity over the last decade has come from users. I think many Stata users would agree that we need "Better tables", but once you start to talk about details, disagreement about what that means becomes more prominent. (I'm oddly reminded of Quine's quirky quip about the ontological problem, for which see (e.g.) <http://sfcmadrid.files.wordpress.com/2010/12/quine-on-what-there-is.pdf> I want to admit that I don't understand anything much after the first paragraph, but the first paragraph is what applies here.) For example, and we would need a big table to be more comprehensive, and there is some guesswork here, but also an attempt at distillation of many threads and discussions at users' meetings, 1. For some, the primary issue is overwhelmingly centred on collation of modelling results, the territory in which -estout- (SJ/SSC), -outreg- (SJ/SSC), -outreg2- (SSC) have each gathered fans. 2. For some, the primary need is at a different level, centred more on counts, percents, means, and other summary statistics. Imagine a consolidation of -tabulate-, -table-, -tabdisp-, -tabstat- to start only at the beginning. Some years ago, a longstanding user who might not want to be quoted on this said to me that Stata should just put all the mainstream tabulation commands into one. I asked if she would still want that if the manual entry was 100 pages long, but she indicated that would be delightful. 3. For some, that means primarily LaTeX support, for others export to MS Office, for yet others XML, and so forth. Some details: On tables as objects . help _tab points to an undocumented command. Ian Watson's -tabout- (SSC) remains one of the most versatile tools for what I think of as supertables. I've got the impression that it's closest to what Rebecca is doing. My -groups- (SJ/SSC) does more than seems widely known, but it's aimed in a different direction. I directed about loosely similar ideas but approached from a graphical angle in SJ-8-2 gr0034 . . . . . . . . . . Speaking Stata: Between tables and graphs (help labmask, seqvar if installed) . . . . . . . . . . . . N. J. Cox Q2/08 SJ 8(2):269--289 outlines techniques for producing table-like graphs Nick On Tue, Oct 30, 2012 at 10:00 PM, Rebecca Pope <rebecca.a.pope@gmail.com> wrote: > Several years ago, Nick Cox posted the text below in a post titled > "Tabling: an agenda". As far as I can tell searching the list and the > documentation, there hasn't been any progress on this agenda item as > of Stata 12. Does anyone know of any new official/user-written > commands that I've failed to discover? > > Absent that, I've attempted to produce a combined table of frequencies > within the constraints as I understand them. Note, this is > task-specific, not as general as what Nick proposed below. I could not > figure out how to use the matrices from -tabulate, matcell() matrow()- > to display the results nicely. Instead, I'm using a series of -table- > commands, saving the results into a temporary data set (successive > -append-s), and using -tabdisp- for the end result. I can get decent > looking output of descriptive stats for all variables of interest in > one table, but it is an inelegant solution. I've included an example > using the auto data at the end of this e-mail so everyone can see my > approach. Is there a better way to produce the resulting table? > > Regards, > Rebecca > > -------------------- > http://www.stata.com/statalist/archive/2003-10/msg00247.html > <snip> > > Problem 2: combining tables > =========================== > > As Phil has clearly highlighted, one common need is to put together > what in effect sub-tables into combined tables. It could be argued > that Stata should not interfere between you and your word and text > processor; any way, at first sight it offers next to no tools for > doing this. > > Available solutions: ... except that, in a sense, there is a bunch of > commands for joining tables so long as they are (expressible as) Stata > matrices. This line of attack is probably under-appreciated; at the > same time, it falls short of what I guess people often need here. > > Required solutions: a whole mini-language for combining tables. In > effect tables could be seen as objects and there would be a set of > operations for combining them, with tunable control of output form: > e.g. join along rows; join along columns; layer. Each combining would > produce alignment, and be more than what anybody could do as a > cut/copy/paste exercise. I guess that this would be a substantial > project for Stata Corp. -graph combine- is a partial analogue. > > (But there's more, such as elementwise addition, subtraction, > multiplication, division of tables...) > > <snip> > ------------------ > > set more off > > sysuse auto.dta, clear > tempfile stats > > /* Calculate table values */ > /* Total & price */ > qui summ price > local total = `r(N)' > > preserve > local lbl2: var label price > clear > set obs 2 > > gen charac = _n > gen freq = `total' in 1 > gen pct = 100 in 1 > gen place = 1 in 1 > gen type = "" in 1 > > replace freq = `r(mean)' in 2 > replace pct = `r(sd)' in 2 > replace place = 2 in 2 > replace type = "cont" in 2 > > save "`stats'" > restore > > /* rep78 */ > preserve > local lbl3: var label rep78 /* preserve original variable label */ > recode rep78 (1/2=3) (3=4) (4=5) /* not recoding 5 because combining 4 with 5 */ > mvencode rep78, mv(6) /* preserve missing, label as such later */ > table rep78, contents(freq) replace > rename rep78 charac > rename table1 freq > gen pct = freq/`total'*100 > gen place = 3 > gen type = "cat" > > append using "`stats'" > save "`stats'", replace > restore > > /* foreign */ > preserve > local lbl4: var label foreign > recode foreign (0=7) (1=8) > mvencode foreign, mv(9) > > table foreign, contents(freq) replace > rename foreign charac > rename table1 freq > gen pct = freq/`total'*100 > gen place = 4 > gen type = "cat" > > append using "`stats'" > > /* Display combined results */ > /* Variable headings for table */ > label var freq "Frequency" > label var charac "Characteristic" > label var pct "Percent" > > /* Combine all value labels for variables in table */ > label def charac 1 "N" 2 "Mean in Dollars (S.D.)" /// > 3 "Poor/Fair" 4 "Average" 5 "Good/Excellent" 6 "Missing/Unknown" /// > 7 "Domestic" 8 "Foriegn" 9 "Missing/Unknown" > label val charac charac > > /* Give display names to value of place variable */ > label def place 1 " " 2 "`lbl2'" 3 "`lbl3'" 4 "`lbl4'" > label val place place > label var place "Variable" > > /* Apply display formats */ > tostring freq, format(%9.1gc) replace force > tostring pct, format(%09.1fc) replace force > replace pct = "(" + pct + ")" if type=="cont" /* because continuous > vars use S.D., not %*/ > > /* Display table of statistics */ > tabdisp charac, cellvar(freq pct) by(place) left concise > restore * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: combining tables***From:*Daniel Feenberg <feenberg@nber.org>

**References**:**st: combining tables***From:*Rebecca Pope <rebecca.a.pope@gmail.com>

- Prev by Date:
**st: combining tables** - Next by Date:
**st: Search Notes** - Previous by thread:
**st: combining tables** - Next by thread:
**Re: st: combining tables** - Index(es):