-crossmat-
Description
The command -crossmat- is a wrapper for built-in Stata command -tabulate-. The idea is that if it is worth showing in the log then it is also worth saving in a matrix.
Matrices can be visualised using -matprint-
-crossmat- is a part of the package matrixtools.
Installation
To install use the command: ssc install matrixtools
Demonstration
We use the Stata example dataset dose.dta:
webuse dose.dta, clear
The command -crossmat- can have one or two variables as arguments. Below is just one:
crossmat dose
In the results from -crossmat- with 1 variable as argument are the matrices:
- r(counts) The count table
- r(pct) The percentages
They can shown using -matprint-;
matprint (r(counts), r(pct)), d((0,1))
----------------------------- Frequency % ----------------------------- Dosage 1/day 32 0.3 2/day 32 0.3 3/day 32 0.3 Total 96 1.0 -----------------------------
With 2 variables the command eg looks like (Note that to see Fisher's exact test in the matrix r(test) the option exact must be set):
crossmat dose function, exact(1)
And the matrices to be retrieved are:
matprint r(counts), d(0)
------------------------------------------ Function < 1 hr 1 to 4 4+ Total ------------------------------------------ Dosage 1/day 20 10 2 32 2/day 16 12 4 32 3/day 10 16 6 32 Total 46 38 12 96 ------------------------------------------
matprint r(expected), d(2)
--------------------------------------------- Function < 1 hr 1 to 4 4+ Total --------------------------------------------- Dosage 1/day 15.33 12.67 4.00 32.00 2/day 15.33 12.67 4.00 32.00 3/day 15.33 12.67 4.00 32.00 Total 46.00 38.00 12.00 96.00 ---------------------------------------------
matprint r(chi2), d(3)
--------------------------------------------- Function < 1 hr 1 to 4 4+ Total --------------------------------------------- Dosage 1/day 1.420 0.561 1.000 2.982 2/day 0.029 0.035 0.000 0.064 3/day 1.855 0.877 1.000 3.732 Total 3.304 1.474 2.000 6.778 ---------------------------------------------
matprint r(lrchi2), d(3)
---------------------------------------------- Function < 1 hr 1 to 4 4+ Total ---------------------------------------------- Dosage 1/day 10.628 -4.728 -2.773 3.128 2/day 1.362 -1.298 0.000 0.064 3/day -8.549 7.476 4.866 3.792 Total 3.441 1.450 2.093 6.984 ----------------------------------------------
matprint r(tests), d((3,0,3))
------------------------------- Test f P ------------------------------- Pearson 6.778 4 0.148 LR 6.984 4 0.137 Fisher's exact 0.145 -------------------------------
matprint r(greeks), d(3)
------------------------------- Estimate ASE ------------------------------- Cramers V 0.188 Gamma 0.369 0.129 Kendalls tau b 0.238 0.086 -------------------------------
matprint r(pct), d(2)
-------------------------------------------- Function < 1 hr 1 to 4 4+ Total -------------------------------------------- Dosage 1/day 0.21 0.10 0.02 0.33 2/day 0.17 0.13 0.04 0.33 3/day 0.10 0.17 0.06 0.33 Total 0.48 0.40 0.13 1.00 --------------------------------------------
matprint 100 * r(pct), d(2)
---------------------------------------------- Function < 1 hr 1 to 4 4+ Total ---------------------------------------------- Dosage 1/day 20.83 10.42 2.08 33.33 2/day 16.67 12.50 4.17 33.33 3/day 10.42 16.67 6.25 33.33 Total 47.92 39.58 12.50 100.00 ----------------------------------------------
matprint 100 * r(rpct), d(2)
---------------------------------------------- Function < 1 hr 1 to 4 4+ Total ---------------------------------------------- Dosage 1/day 62.50 31.25 6.25 100.00 2/day 50.00 37.50 12.50 100.00 3/day 31.25 50.00 18.75 100.00 Total 47.92 39.58 12.50 100.00 ----------------------------------------------
matprint 100 * r(cpct), d(2)
----------------------------------------------- Function < 1 hr 1 to 4 4+ Total ----------------------------------------------- Dosage 1/day 43.48 26.32 16.67 33.33 2/day 34.78 31.58 33.33 33.33 3/day 21.74 42.11 50.00 33.33 Total 100.00 100.00 100.00 100.00 -----------------------------------------------
Last update: 2022-04-19, Stata version 17