-tab2mat- and -rcolp2mat- are now available on SSC (e.g. ssc install tab2mat) which saves tabulations as matrices with appropriate labels. This can be especially useful when exporting results to other files such as excel or word (e.g. see -putexcel-).
Example of tab2mat: There are also options to exclude/include totals, or only report frequencies and/or percentages.
Example of rcolp2mat: Save row or column percents of a two-way table of frequencies to specified matrix. There are also options to include total % or add Ns.
Example of tab2mat: There are also options to exclude/include totals, or only report frequencies and/or percentages.
Code:
. sysuse nlsw88.dta, clear (NLSW, 1988 extract) . tab race race | Freq. Percent Cum. ------------+----------------------------------- white | 1,637 72.89 72.89 black | 583 25.96 98.84 other | 26 1.16 100.00 ------------+----------------------------------- Total | 2,246 100.00 . tab2mat race, matrix(A) total A[4,2] Freq Percent white 1637 72.885129 black 583 25.957257 other 26 1.1576135 Total 2246 100
Code:
. sysuse nlsw88.dta (NLSW, 1988 extract) . tab race union, row nof | union worker race | nonunion union | Total -----------+----------------------+---------- white | 77.68 22.32 | 100.00 black | 69.86 30.14 | 100.00 other | 66.67 33.33 | 100.00 -----------+----------------------+---------- Total | 75.45 24.55 | 100.00 . rcolp2mat race union, matrix(A) row total A[4,2] nonunion union white .77679231 .22320769 black .69860279 .30139721 other .66666667 .33333333 Total % .75452609 .24547391 . rcolp2mat race union, matrix(A) row detail A[4,3] nonunion union Total N white .77679231 .22320769 1353 black .69860279 .30139721 501 other .66666667 .33333333 24 Total N 1417 461 1878