Many tables in one document – flexmat


flexmat can create many tables in a single document or multiple documents. Also, flexmat can be used within a loop or without a loop. The following example shows how flexmat can be used to create multiple tables in a single document. The example uses a loop. For exporting these tables to MS Word / Excel / LaTeX / HTML, we can use either the default file name of asdocx – MyFile.docx – or a different name. If we wish to use a different file name, we need to use the option setfile with asdocx before starting the flexmat process.

asdocx setfile, save(My own filename.docx)

 

Example code


 

* Start with clean slate
flexmat reset

*Store the first table in location 1
local next 1

* Loop over three groups
local results subgroup1 subgroup2 subgroup3 

foreach r of local results {

  flexmat addparts, title(Table 1: Marginal WTP for Ground Beef Attribute - `r')  location(`next') 
  flexmat addrow, data("Ground Beef - Attribute", "PUSA - Mean", "PUSA - 95% CI", "PUSA - % increase", "Four Def - Mean ", "Four Def - 95% CI", "Four - % increase") row(1) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 2", `ma2`r'd1', "`lbat2`r'd1' - `ubat2`r'd1'", `pc2`r'd1', `ma2`r'd2', "`lbat2`r'd2' - `ubat2`r'd2'", `pc2`r'd2' ) row(2) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 3", `ma3`r'd1', "`lbat3`r'd1' - `ubat3`r'd1'", `pc3`r'd1', `ma3`r'd2', "`lbat3`r'd2' - `ubat3`r'd2'", `pc3`r'd2' ) row(3) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 4", `ma4`r'd1', "`lb4`r'd1' - `ub4`r'd1'", `pc4`r'd1', "N/A", "N/A", "N/A" ) row(4) col(1)  dec(2) location(`next') 
  flexmat addrow, data("Attribute 42", "N/A", "N/A", "N/A", `ma42`r'd2', "`lb42`r'd2' - `ub42`r'd2'", `pc42`r'd2') row(5) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 43", "N/A", "N/A", "N/A", `ma43`r'd2', "`lb43`r'd2' - `ub43`r'd2'", `pc43`r'd2') row(6) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 44", "N/A", "N/A", "N/A", `ma44`r'd2', "`lb44`r'd2' - `ub44`r'd2'", `pc44`r'd2') row(7) col(1) dec(2) location(`next') 
        
 * Increment the location to store a new table
 loc ++next
         
  * Add table parts: title and notes
  flexmat addparts, title(Table 2: Marginal WTP for NY Strip Attribute - `r') location(`next')  
  flexmat addrow, data("Steak - Attribute", "PUSA - Mean", "PUSA - 95% CI", "PUSA - % increase", "Four Def - Mean ", "Four Def - 95% CI", "Four - % increase") row(1) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 2", `ma2`r'd3', "`lbat2`r'd3' - `ubat2`r'd3'", `pc2`r'd3', `ma2`r'd4', "`lbat2`r'd4' - `ubat2`r'd4'", `pc2`r'd4' ) row(2) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 3", `ma3`r'd3', "`lbat3`r'd3' - `ubat3`r'd3'", `pc3`r'd3', `ma3`r'd4', "`lbat3`r'd4' - `ubat3`r'd4'", `pc3`r'd4' ) row(3) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 4", `ma4`r'd3', "`lb4`r'd3' - `ub4`r'd3'", `pc4`r'd3', "N/A", "N/A", "N/A" ) row(4) col(1)  dec(2) location(`next') 
  flexmat addrow, data("Attribute 42", "N/A", "N/A", "N/A", `ma42`r'd4', "`lb42`r'd4' - `ub42`r'd4'", `pc42`r'd4') row(5) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 43", "N/A", "N/A", "N/A", `ma43`r'd4', "`lb43`r'd4' - `ub43`r'd4'", `pc43`r'd4') row(6) col(1) dec(2) location(`next') 
  flexmat addrow, data("Attribute 44", "N/A", "N/A", "N/A", `ma44`r'd4', "`lb44`r'd4' - `ub44`r'd4'", `pc44`r'd4') row(7) col(1) dec(2) location(`next') 

* Increment the location to store a new table
  loc ++next

 * Add table parts: title and notes
  flexmat addparts, title(Table 5: Marginal WTP for Pork Tenderloin Attribute - `r') location(`next')  
  flexmat addrow, data("Pork - Attribute", "PUSA - Mean", "PUSA - 95% CI", "PUSA - % increase", "Four Def - Mean ", "Four Def - 95% CI", "Four - % increase") row(1) col(1) dec(2)  location(`next')  
  flexmat addrow, data("Attribute 2", `ma2`r'd5', "`lbat2`r'd5' - `ubat2`r'd5'", `pc2`r'd5', `ma2`r'd6', "`lbat2`r'd6' - `ubat2`r'd6'", `pc2`r'd6' ) row(2) col(1) dec(2)  location(`next')  
  flexmat addrow, data("Attribute 3", `ma3`r'd5', "`lbat3`r'd5' - `ubat3`r'd5'", `pc3`r'd5', `ma3`r'd6', "`lbat3`r'd6' - `ubat3`r'd6'", `pc3`r'd6' ) row(3) col(1) dec(2)  location(`next')  
  flexmat addrow, data("Attribute 4", `ma4`r'd5', "`lb4`r'd5' - `ub4`r'd5'", `pc4`r'd5', "N/A", "N/A", "N/A" ) row(4) col(1)  dec(2)  location(`next')  
  flexmat addrow, data("Attribute 42", "N/A", "N/A", "N/A", `ma42`r'd6', "`lb42`r'd6' - `ub42`r'd6'", `pc42`r'd6') row(5) col(1) dec(2)  location(`next')  
  flexmat addrow, data("Attribute 43", "N/A", "N/A", "N/A", `ma43`r'd6', "`lb43`r'd6' - `ub43`r'd6'", `pc43`r'd6') row(6) col(1) dec(2)  location(`next')  
  flexmat addrow, data("Attribute 44", "N/A", "N/A", "N/A", `ma44`r'd6', "`lb44`r'd6' - `ub44`r'd6'", `pc44`r'd6') row(7) col(1) dec(2)  location(`next')  
 
 loc ++next
}

asdocx export