I use putdocx to create standardized outputs for my statistical analyses. I am writing an own command to create a "table of contents" in the beginning of the document. The table of contents is actually a table where each row contains the text of a caption, as a cross-reference link to the corresponding paragraph (using bookmarks). Rows are added flexibly when a new caption is added to the document.
Besides linking the captions to the paragraphs, I would like to add page numbers to the TOC as well, so that it is easier to read the file when reading in printed form. However, I am struggling to find any solution for that other than hard-coding the page number in my do-files.
I found that field codes for Word documents might be the solution, specifically the "PAGEREF bookmark" field code (see https://support.microsoft.com/en-US/...-pageref-field). However, I don't know how to insert a field code into a table cell (or as regular text) using Stata.
From my docx outputs I know that Stata adds page numbers in the footer as field codes, using some Mata commands. However I am not familiar with Mata coding so I cannot follow what's happening in the putdocx code and I cannot copy/alter it for my purposes.
Can anybody help me out with a solution?
Besides linking the captions to the paragraphs, I would like to add page numbers to the TOC as well, so that it is easier to read the file when reading in printed form. However, I am struggling to find any solution for that other than hard-coding the page number in my do-files.
I found that field codes for Word documents might be the solution, specifically the "PAGEREF bookmark" field code (see https://support.microsoft.com/en-US/...-pageref-field). However, I don't know how to insert a field code into a table cell (or as regular text) using Stata.
From my docx outputs I know that Stata adds page numbers in the footer as field codes, using some Mata commands. However I am not familiar with Mata coding so I cannot follow what's happening in the putdocx code and I cannot copy/alter it for my purposes.
Can anybody help me out with a solution?

Comment