
There is also Stata’s dyndoc command, which converts a text file into an HTML file or Word document. This is an end of file marker which evaluates to 1 when file read reaches the end of the file. Stata is promoting its pystata Python package, which allows you to run Stata in an IPython environment like Jupyter notebooks. Here, I used r(eof) to condition my while loop. Then the solution becomes something along the lines of: clear *įile open myfile using "/path/to/my/file/SqlScript.sql", readĪnd the result: SELECT * FROM MyTable WHERE Condition sql file at /path/to/my/file/ titled SqlScript.sql with the following contents: SELECT * Now, there is a very simple loop construct that allows us to read line by line and store the contents into the macro. Any kinds of data files can be converted into STATA data files by using Stat-Transfer (from STATA Corporation). Step 2: At the dialog box SAVE AS: Type in a file name of your choosing.
#Copy log file into word stata how to
Stata version 12 How to Create a Log of Your Session in log format. Consider Stata’s opening windowor windows, to be more precise (Figure 1-1). When you click on the icon, a file untittled. Start Stata as you would start any program. This is actually a convenience if you are writing to a file with file write because you won't have to embed newline characters in the string you wish to write - each call to file write will write a new line. (a file that contains Stata syntax) x How to create a log file (a file that saves your commands and results) x How to print output and how to copy/paste output into Word x How to use Stata’s help system Let’s start with a brief tour of the Stata interface. "The file is positioned at the top (tof), so the first file read reads at the beginning of the file." For example, we can nest five do files in one master do file using: do 1.unziprawfiles.do do 2.stockdata.do do 3.sectordata.do do 4.indexdata.do do 5.announcements.do. You only get the first line of the file when you execute file read myfile x because, according to the documentation at help file: It is a smart idea to have one master do file and have all the other do files (if you must use more than one) nested within it.

For example, this approach might even seem silly next to something like a BufferedReader in Java, but I digress. I can also understand why the solution may seem hacked up, especially for somebody coming from a programming language.

My preferred solution is the "hacked up, read the file line by line and concatenate" solution.
