Hi, in Stata 14, it is now possible to create a PDF using mata, something I appreciate very much.
But, I am struggling to get the 'basics' to work. For example, with this example code, it is possible to create multiple file names and display them in Stata's result window:
or
The above two examples are fine for me because the string of text is like "filepath_filename`i'.pdf".
Now I want to implement this in mata code so that multiple PDF's are created. I tried:
But, this results in errors:
type mismatch: exp.exp: transmorphic found where struct expected
expression invalid
Probably, I am too ignorant working with mata to get this right. So, any help is much appreciated.
But, I am struggling to get the 'basics' to work. For example, with this example code, it is possible to create multiple file names and display them in Stata's result window:
Code:
global filepath "C:\YourFolder"
mata
mata clear
text = "a","b","c"
pdft = ".pdf"
for(i=1;i<=length(text);++i) {
myname = "$filepath`'\Example_file_"+text[i]+pdft[1]
myname
}
end
Code:
global filepath "C:\YourFolder"
mata
mata clear
pdft = ".pdf"
for (i=1; i<=3; i++) {
myname = "$filepath`'\Example_file_"+sprintf("%02.0f",i)+pdft[1]
myname
}
end
Now I want to implement this in mata code so that multiple PDF's are created. I tried:
Code:
global filepath "C:\YourFolder"
mata
mata clear
pdft = ".pdf"
for (i=1; i<=10; i++) {
pdf = PdfDocument()
pdf.setPageSize("A4")
pdf.save("$filepath`'\Example_file_"+sprintf("%02.0f",i)+pdft[1])
pdf.close()
}
end
type mismatch: exp.exp: transmorphic found where struct expected
expression invalid
Probably, I am too ignorant working with mata to get this right. So, any help is much appreciated.

Comment