asdocx: Export from Stata to Word, Excel, LaTeX & HTML › Forums › asdocx Forum › Creating Multiple Custom Tables at Once Using Flexmat, Then Output To One Doc? › Reply To: Creating Multiple Custom Tables at Once Using Flexmat, Then Output To One Doc?
Thanks for bringing this up. I have improved the functionality of flexmat, and as a result, I have updated the asdocx files. To get the updates, use
asdocx_update
This thread will be useful to other users of asdocx and flexmat, therefore, I will provide a detailed reply.
The appendmat
sub-command appends a flexmat file to the current asdocx file (that is is available in the global macro $active_flexmat_file
). Users must use the option matname()
when using appendmat()
. The subcommand is similar to addmat
, but with three main differences:
1. Users do not have to specify the location()
option as appendmat
automatically identifies the next available location and appends the flexmat file to it.
2. Files written with flexmat are stored as associative arrays, therefore, they need to be converted back to matrices before appending them to other files. The sub-command appendmat
takes care of this.
3. The addmat
subcommand can be used to add a matrix at any combination of rows and columns, potentially replacing an existing matrix or table. In contrast, the appendmat
command will always append the flexmat file to a new location, resulting in the addition of a new table to the file.
Here is a typical use of the sub-command appendmat
.
* Specify the flexmat filename using asdocx asdocx setfile, save(First_Test) * Add contents to the file First_Test flexmat addrow, data(Year, Month, Day) r(1) flexmat addrow, data(2001, March, 21) r(2) * Add notes and title to the table flexmat addparts, title(Table: Test Results for Sample A) /// notes(Sample A was tested for contaminants X, Y, and Z.) * Create another flexmat file and add contents asdocx setfile, save(Second_Test) flexmat addrow, data(Make, Model, mpg) r(1) flexmat addrow, data(Ford, Explorer, 15) r(2) * Add notes and title to the table flexmat addparts, title(Table: Test Results for Sample B) /// notes(Sample B was tested for contaminants A, B, and C) * Create asdocx file and append the earlier two flexmat files to it asdocx, save(REPORT) text(MY REPORT) title replace flexmat appendmat, matname(First_Test) flexmat appendmat, matname(Second_Test) * Export the asdocx file to MS Word asdocx export
* Note on file names
The setfile
option of ‘asdocx’ causes ‘flexmat’ to store its files in the _asdoc
folder, located in the user’s current directory. This folder is hidden by default to avoid visual clutter and accidental deletion. In the examples given, the files First_Test
and Second_Test
are stored as First_Test.flexmat
and Second_Test.flexmat
, respectively, in the hidden directory. Users do not need to specify the folder path or the extension, as flexmat automatically retrieves files from the hidden the directory and adds the .flexmat
extension.
When users are confident that they no longer need to store the asdocx’s working files, they can use:
asdocx clear
This will delete all raw files in the “_asdoc” folder.