Adding Column Headers

Adding Column Headers

by Ilana Garcia-Grossman -
Number of replies: 1

Hello,

I am struggling with figuring out how to create column headers that will export via putdocx. Similar to the provided final exam example, I wanted to be able to add a column header that identifies which variable the summary stastistics belong to (in final exam example there is a non-diabetes and diabetes header over the N, Mean, and SD).

 I was able to figure out that you can add a multi-level column header using colnames, but then it doesn't seem to export to putdocx. For example using the final exam matrix colnames MATRIX NAME="N" "Non-Diabetes:mean" "SD" "N" Diabetes:SD" "N" would create an additional row with the non-diabetes and diabetes column headers. However, they don't export to the word doc (I included rownames colnames). Perhaps there is a way to export to putdocx? Other another strategy entirely?

Any guidance would be much appreciated!  

Thanks!

Ilana

In reply to Ilana Garcia-Grossman

Re: Adding Column Headers

by Crystal Langlais -
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!