Dear Statalisters,
I am getting an error regarding the option layout() of putdocx table. Have tried this in Stata versions 16.1 and 18.0 and getting the same error. Have looked through documentation and forums and not finding anything, hence this post.
Here is a nice little working example for when one wants to output a publishable quality table of raw data that contains strings. In other words one cannot use a matrix for esttab or outreg or frmttable. I have marked where the error happens as a comment below the corresponding command.
Thanks for looking and any input!
I am getting an error regarding the option layout() of putdocx table. Have tried this in Stata versions 16.1 and 18.0 and getting the same error. Have looked through documentation and forums and not finding anything, hence this post.
Here is a nice little working example for when one wants to output a publishable quality table of raw data that contains strings. In other words one cannot use a matrix for esttab or outreg or frmttable. I have marked where the error happens as a comment below the corresponding command.
Thanks for looking and any input!
Code:
sysuse auto, clear
* change the label of foreign to a single letter
label define foreign 0 D 1 F, modify
label values foreign foreign
* create a rank by best repair record and descending price
gsort - rep78 price
gen rank = _n
sort rank
order rank
putdocx begin
* add data to table
putdocx table tbl = data(rank make rep78 price mpg foreign), varnames
* set font and alignment for whole table
putdocx table tbl(.,.), font("Times New Roman") border(all, nil) halign(center)
*layout(autofitcontents) - not working
* name columns
putdocx table tbl(1,1) = ("Rank by Repair record and price"), font("Times New Roman") halign(center)
putdocx table tbl(1,2) = ("Make"), font("Times New Roman") halign(center)
putdocx table tbl(1,3) = ("Repair record"), font("Times New Roman") halign(center)
putdocx table tbl(1,4) = ("Price"), font("Times New Roman") halign(center)
putdocx table tbl(1,5) = ("MPG"), font("Times New Roman") halign(center)
putdocx table tbl(1,6) = ("Domestic/Foreign"), font("Times New Roman") halign(center)
* adjust formatting of columns as needed
* integers
foreach i in 1 3 5 6 {
putdocx table tbl(.,`i'), nformat(%4.0f)
}
* dollars
loc i 4
putdocx table tbl(.,`i'), nformat(%9.0fc)
* add borders
putdocx table tbl(1,.), border(top, thick) border(bottom, single) border(start, nil) border(end, nil)
qui sum rank
local last = `r(max)' + 1
putdocx table tbl(`last',.), border(bottom, thick) border(start, nil) border(end, nil)
* close and save
putdocx save auto_repair_rank, replace

Comment