In a text, you often you refer to a number (e.g. the number of observations in the estimation sample). There is a simple way to automise the export of this number from a Stata-do-file to a Latex-document. It works by generating another latex-document, which contains this number only. This newly created file can be included in the main latex-document. Here is how it works (example here: number of observations, where id
is the identifier for individuals):
tab id
file open newfile using numberofobs.tex, write replace
file write newfile “`r(r)’”
file close newfile
This syntax generates the number of distinct values of variable id
.
This syntax can also be used to export single numbers to other programs, such as MS Word or MS Excel.
In MS Word, it works as follows:
1) generate the separate file as described above
2) in MS Word: go to INSERT–>FIELD; choose function INSERTTEXT. There, you have to enter the files path. That’s it
Using MS Word’s update function, the file (and the corresponding numbers) can easily be changed