


View each macro with the -display- opening tick (`), to the left of the number 1 on your keyboard, the macro name, and a closing apostrophe (‘).Use macros to extract the as beta coefficient, and as the 95% confidence intervals, and as the p-value for each row.Run a regression for the first three rows of our table, saving the r(table) matrix for each regression as our custom matrix (row1-3).Remember the numbers from above? We’ll use those numbers to extract the matrix cell results into macros. We just need to point the macro at the right matrix cell in order to extract the cell’s results. Later on, use can use that ‘codeword’ associated with the macro to make Stata blurt out the stored cell result. You can pluck a cell of a matrix and store it as a macro. Macros are little ‘codewords’ that represent another variable or string. matrix list row1Įform 0 0 Let’s extract the matrix components of interest as macros! I bolded/underlined the first to highlight this. Note that the beta coefficient is at, the 95% confidence interval bounds are at and, and the p-value is at 4,1]. The stata output for the last three lines should look like the output below. Then, we will confirm that each row is saved by plopping the command to view the matrices at the end.We’ll specifically call them “row1”, “row2”, and “row3”. Save the r(table) matrix for each regression to a custom named matrix.Run three regressions, one for each row, and.Use the -matrix- command to copy the contents of the r(table) to a custom matrix. Since we actually need to save 3 separate r(table) matrices to fill out the blank table (one for each row), you should do this anyway to help facilitate completing the table. Make sure to save the r(table) matrix as custom matrix before going any further.

įor various reasons that you can read about here, r(table) is not a usual matrix and Stata will do funny things if you try to run matrix commands on it. You’ll note above (after the -matrix list r(table)- command) that Stata tells you that the r(table) matrix has 9 rows and 2 columns, or. These exist separate from the dataset, which is also basically a big spreadsheet. Matrices are basically small spreadsheets saved in the memory that can be accessed by referencing a cell reference. Copy it to a custom ‘typical’ matrix before doing anything else!
#STATA CROSSTAB HOW TO#
You can either copy the output manually, or automate it! Let’s learn how to automate this process. In Stata you’ll run three regressions to fill out the three rows: sysuse auto, clear We want to regress MPG (Y) on weight (x) overall and by strata of domestic vs. Let’s use the classic 1978 auto dataset that comes with Stata. Here’s one step-by-step approach that you might find helpful. Extracting the results from regressions in Stata can be a bit cumbersome. If you make your own Stata programs and loops, you have discovered the wonders of automating output of analyses to tables.
