do nlsw_data_setup tabout south race union sex using table1.tex, replace /// c(freq col) f(0c 1) style(tex) font(bold) twidth(11) /// title(Table 1: A Simple Example) fn(Source: nlsw88.dta) tabout south race union sex using table2.tex, replace /// c(col row) f(1) style(tex) font(italic) twidth(13) /// title(Table 2: Including the sample size) /// fn(Source: nlsw88.dta) npos(both) nlab(Obs) tabout south race union sex using table3.tex, /// replace style(tex) font(italic) twidth(13) /// c(col row) f(1) npos(both) nlab(Obs) /// layout(cb) h3(nil) /// title(Table 3: Further refinements, /// using column block layout (%)) /// fn(Source: nlsw88.dta) do cancer_data_setup tabout stime died using table4.tex, replace /// c(freq col cum) style(tex) font(italic) twidth(14) /// f(0 1) clab(No. Col_% Cum_%) title(Table 4: Example /// of a simple cross tabulation) fn(Source: cancer.dta) do nlsw_data_setup tabout south race collgrad [iw=wt] using table5.tex, /// replace style(tex) font(bold) c(freq row col) /// f(0c 1 1) layout(rb) h3(nil) twidth(11) /// title(Table 5: Example of cross tabulation /// using panels) fn(Source: nlsw88.dta) tabout south race collgrad [iw=wt] using table6.tex, /// replace style(tex) font(bold) c(freq row col) /// f(0c 1p 1p) layout(rb) clab(_ _ _) h3(nil) twidth(11) /// title(Table 6: Same example with refinements) /// fn(Source: nlsw88.dta) tabout south collgrad race using table7.tex, replace /// style(tex) font(bold) c(col) f(1) npos(row) /// twidth(12) clab(Col_%) stats(chi2) title(Table 7: /// Example of sample counts and stats) fn(nlsw88.dta) tabout south collgrad race using table8.tex, replace /// style(tex) font(bold) c(col) f(1) clab(Col_%) /// twidth(14) stats(chi2) stpos(col) stlab(Chi2) /// stform(2) plab(Signif) stars npos(row) /// nlab(Sample size) title(Table 8: Same example with /// customisation) fn(nlsw88.dta) tabout industry occupation [iw=wt] using table9.tex, /// replace style(tex) font(bold) oneway c(freq col cum) /// f(0c 1) clab(Count Col_% Cum_%) twidth(11) npos(col) /// nlab(Sample) title(Table 9: A oneway table) /// fn(Source: nlsw88.dta) sysuse auto, clear tabout rep78 foreign using table10.tex, replace /// style(tex) font(italic) c(mean weight) f(0c) sum /// twidth(9) h1(Car type (mean weight in lbs.)) h3(nil) /// title(Table 10: Simple twoway summary table of means) /// fn(auto.dta) sysuse voter, clear tabout inc candidat using table11.tex, replace /// style(tex) font(italic) c(median pfrac) f(1) clab(%) /// sum twidth(9) title(Table 11: Simple twoway summary /// table of medians) fn(voter.dta) sysuse auto, clear tabout foreign rep78 using table12.tex, replace /// style(tex) font(bold) twidth(13) sum npos(tufte) /// c(mean mpg mean weight mean length median price /// median headroom) f(1c 1c 1c 2cm 1c) h2(Mean Median) /// h2c(3 2) clab(MPG Weight_(lbs) Length_(in) Price /// Headroom_(in)) title(Table 12: Oneway summary table /// \\ with multiple summary measures) fn(Source: auto.dta) do cancer_data_setup tabout died drug using table13.tex, replace /// style(tex) font(italic) twidth(12) sum f(1) /// c(mean age iqr age median studytime min studytime /// max studytime) title(Table 13: Oneway summary table /// with default headings) fn(Source: cancer.dta) tabout died drug using table14.tex, replace /// style(tex) font(italic) twidth(12) sum f(1) /// c(mean age iqr age median studytime min studytime /// max studytime) h2c(2 3) ltrim(1) h2(Patient_age_(yrs) /// Length_of_study_(mths)) clab(Mean IQR Median Minimum /// Maximum) title(Table 14: Same oneway summary table /// \\ with customised headings) fn(\emph{Source}: /// cancer.dta. Note that IQR is interquartile range) use "http://www.stata-press.com/data/r14/nhanes2b", clear svyset psuid [pweight=finalwgt], strata(stratid) svy: tabulate race diabetes, row ci format(%7.3f) svy: tabulate sex diabetes, row ci format(%7.3f) la var race "Race" la var sex "Sex" la var diabetes "Diabetes" la def ny 0 "No" 1 "Yes", modify la val diabetes ny tabout race sex diabetes using table16.tex, replace /// style(tex) font(italic) twidth(16)c(row ci) svy f(3) /// stats(chi2) cisep(-) h2c(2 2 1) ltrim(2) npos(col) /// nlab(Sample size) title(Table 16: Survey data example) /// fn(Source: nhanes2b) tabout race sex diabetes using table17.tex, replace /// style(tex) font(italic) twidth(16) c(row lb ub) svy /// stats(chi2) f(3) dpc npos(col) nlab(Obs) /// title(Table 17: Survey data example with /// lb and ub options) fn(Source: nhanes2b. /// Note: lb lower bound; ub upper bound.) tabout race sex diabetes using table18.tex, replace /// style(tex) font(italic) twidth(12) c(row se) svy /// stats(chi2) f(1 3) mult(100) npos(col) h2c(2 2 1) /// nlab(Obs) title(Table 18: Survey data /// example with standard errors) fn(Source: nhanes2b.) tabout race sex diabetes using table19.tex, replace /// style(tex) font(italic) twidth(14) c(row se) svy /// f(1 3) mult(100) seb npos(col) nlab(Obs) plab(Signif) /// h2c(2 2 1) stats(chi2) stpos(col) ppos(only) stars /// title(Table 19: Survey data with stars for /// significance) fn(Source: nhanes2b.) do nlsw_data_setup svyset [pw=wt] tabout occupation south race collgrad using /// table20.tex, replace style(tex) font(italic) sum svy /// c(mean wage se) f(2 2) clab(Mean_wage SE) npos(lab) /// h2c(2 2 2) twidth(15) title(Table 20: Twoway summary /// table with survey data) fn(Source: nslw88.dta) tabout occupation south collgrad using table21.tex, /// replace style(tex) font(italic) twidth(12) layout(row) /// c(mean wage ci) f(2 2) clab(_ (90%_CI)) sum svy /// level(90) npos(lab) h3(& \multicolumn{3}{c} /// {Average wage} \\) title(Table 21: Twoway summary /// table with row layout) fn(Source: nslw88.dta) tabout south sex union race [iw=wt] /// using table22.tex, replace style(tex) /// font(bold) c(freq row) f(0c) twidth(14) /// h2c(2 2 2 2) title(Table 22: Unnecessary /// columns) fn(Source: nlsw88.dta) tabout south sex union race [iw=wt] /// using table23.tex, replace style(tex) /// font(bold) c(freq row) f(0c) twidth(12) /// dropc(6 7 9) show(prepost) clab(No. Row_%) /// h2c(2 2 1) title(Table 23: Dropping columns) /// fn(Source: nlsw88.dta. Note that "Other" /// category has been omitted, so totals will /// not be accurate.) do nlsw_data_setup tabout south sex race union [iw=wt] /// using table24.tex, replace style(tex) /// font(bold) c(freq col) f(0c) twidth(14) /// dropr(3:5) show(prepost) h2c(2 2 2) /// title(Table 24: Dropping rows) /// fn(Source: nlsw88.dta. Note that "Other" /// category has been omitted, so totals will /// not be accurate.) tabout south pregnant union race sex [iw=wt] /// using table25.tex, replace style(tex) /// font(bold) c(freq col) f(0c) twidth(14) /// title(Table 25: Problem with gaps) /// fn(Source: nlsw88.dta) tabout south pregnant union race sex [iw=wt] /// using table26.tex, replace style(tex) /// font(bold) c(freq col) f(0c) twidth(14) /// plugc(2:2 2:3) plugsym(NA) show(prepost) /// title(Table 26: Plugging columns) /// fn(Source: nlsw88.dta) tabout pregnant south union race sex [iw=wt] /// using table27.tex, replace style(tex) /// font(bold) c(freq col) f(0c) twidth(14) /// plugc(1:2 1:3) show(prepost) /// title(Table 27: Plugging columns - a problem) /// fn(Source: nlsw88.dta) tabout pregnant south union race sex [iw=wt] /// using table28.tex, replace style(tex) /// font(bold) c(freq col) f(0c) twidth(14) /// plugc(1:2 1:3) /// h2(Male Female Total) h2c(2 2 2) /// h3(No. % No. % No. %) h3c(1 1 1 1 1 1) /// title(Table 28: Plugging columns - /// fixing the problem) fn(Source: nlsw88.dta) svyset [pw=wt] tabout south collgrad /// using table29.tex, replace style(tex) /// font(italic) twidth(12) c(mean wage ci) /// f(2 2) clab(_ _ _) sum svy /// level(90) npos(lab) layout(row) /// h3(Average_wage) h3c(3) /// title(Table 29: Twoway summary table /// showing use of h3c) fn(Source: nslw88.dta) tabout south union race sex pregnant [iw=wt] /// using table30.tex, replace style(tex) /// font(bold) c(freq row) f(0c) twidth(12) /// title(Table 30: Plugging rows - the problem) /// fn(Source: nlsw88.dta) tabout south union race sex pregnant [iw=wt] /// using table31.tex, replace style(tex) /// font(bold) c(freq row) f(0c) twidth(12) /// plugr(4:3) pluglab(Male*) plugsym(0) /// title(Table 31: Plugging rows - the solution) /// fn(Source: nlsw88.dta. Note: * No male /// pregnancies have been reported.) tabout industry occupation [iw=wt] /// using table32.tex, tp(oneway_basic_b.txt) /// title(Table 32: A oneway table using a template) tabout industry occupation [iw=wt] /// using table33.tex, replace style(tex) /// font(bold) oneway c(freq col cum) f(0c 1) /// clab(Count Col_% Cum_%) /// twidth(11) npos(col) nlab(Sample) /// topf(title.txt) botf(footnote.txt) /// topstr(33|Illustrating use of topf and botf) /// botstr(nlsw88.dta) sysuse auto, clear sum weight local meanwt = r(mean) local meanwt: di %3.2f `meanwt' sum length local meanlen = r(mean) local meanlen: di %3.2f `meanlen' local obs = r(N) tabout rep78 foreign using table34b.tex, /// replace style(tex) font(italic) /// c(mean weight) f(0c) sum twidth(9) /// h1(Car type (mean weight in lbs.)) h3(nil) /// title(Table 34: Short report example) /// fn(auto.dta) topf(topblock.txt) /// topstr(`meanwt'| `meanlen') /// botf(bottomblock.txt) botstr(`obs'|$S_DATE) global tex "/usr/local/texlive/2015/bin/x86_64-darwin" sysuse auto, clear sum weight local meanwt = r(mean) local meanwt: di %3.2f `meanwt' sum length local meanlen = r(mean) local meanlen: di %3.2f `meanlen' local obs = r(N) tabout rep78 foreign using table35.tex, /// replace style(tex) font(italic) /// c(mean weight) f(0c) sum twidth(9) /// h1(Car type (mean weight in lbs.)) h3(nil) /// title(Table 35: Example with font families) /// fn(auto.dta) topf(topblock.txt) /// topstr(`meanwt'| `meanlen') /// botf(bottomblock.txt) botstr(`obs'|$S_DATE) /// family(Adobe Garamond Pro|Arial) ssf /// body comp open show(comp) do nlsw_data_setup tabout race south collgrad using table36.tex, /// replace style(tex) font(bold) /// c(freq row col) f(0c 1 1) /// layout(cb) h1(nil) /// h3(No. %) h3c(3 6) ltrim(-0.5) /// rotate(60) noplines /// landscape /// title(Table 36: Example of rotation /// and no panel lines) /// fn(nlsw88.dta) tabout race south collgrad using table37.tex, /// replace style(tex) font(bold) /// c(freq row col) f(0c 1 1) /// layout(cb) h1(nil) h3(nil) /// rotate(75) noplines twidth(18) /// landscape /// title(Table 37: Example of rotation, /// no panel lines and landscape mode) /// fn(nlsw88.dta) do nlsw_data_setup tabout race south using table38.tex, /// replace style(tex) font(bold) /// c(freq row) f(0c 1) doctype(report) /// caplab(racebysouth) cappos(below) /// title(Example of caption below table) /// fn(nlsw88.dta)