Adding Column Headers

Re: Adding Column Headers

by Crystal Langlais -
Number of replies: 0
Hi Ilana,

Thanks for posting. Let me start by saying that for the purposes of the final, it is perfectly acceptable to add the 2nd level labels (in this example, "Diabetes" and "Non-Diabetes") in Word after you have exported your table.

If you are looking for guidance moving forward, here is what I can provide:

You are correct that you can do multilevel labels for your matrix, though a slight tweak to your code may improve the output:
matrix colnames matrixname="Non-Diabetes: N" "Non-Diabetes: mean" "Non-Diabetes: SD" "Diabetes: N" "Diabetes: mean" "Diabetes: SD"
(note: you could just provide the "non-diabetes:" and "diabetes:" labeling only once and output would probably be the same).

Unfortunately, I'm not aware of an easy way to then export these multilevel labels on matrices. (Does anyone else know a trick?) You could play around with creating matrices of strings (comprised of your column names) of dimension 1Xncols. From this example: one of these matrices would have the "Diabetes" and "Non-Diabetes" names with some empty cells. If you go this route, you could also create a matrix of the 2nd level of column names (for example: "N" "Mean" "SD" "N" "Mean" "SD"). You could then combine these with your matrix full of numerical data:

matrix final = matrix_level1colnames \ matrix_level2colnames \ matrix_withdata

This should export as desired because you are no longer attempting to export just labels but rather string "data". You can use "help matrix" to read about creating matrices of strings.

Hope this helps!