In this post, code line starts with the “.”
Install tab2docx package from the internet:
. net install http://www.stata.com/users/kcrow/tab2docx /
Setup Working Directory (This is optional step. However, you should know where you saved your file at the end when you don’t set up working directory. Usually it is the document folder in your computer.):
. cd “<Path to the folder>” (Usually I create another folder inside folder with data and name it result and set it up as a working directory).
Import Data File (in Excel Format; you can do any type of data):
. import excel “path to data folder\data.xlsx”, sheet(“name of data sheet”) firstrow case(lower)
Note: You can do this step manually using import under file tab. Usually, I do it manually first, then I copy code in the result screen and use that code again and again for future use.
Put results directly into Microsoft Word file (.docx format):
. putdocx begin / *Create Document and Start the Process to put document in Word format */
. putdocx paragraph /* Create Paragraph* /
. putdocx text (“Name of your table or variable you are summarizing “), bold /* Give Name to Table* /
. tab2docx (<variable name>) /* Use this command individually for each variable you want to summarize. Put name of variable inside parenthesis */
. tab2docx (<variable name>)
Note: You can calculate frequency distribution of two different variables in same word file using this command because I use “tab2docx” twice
. putdocx save testfile1.docx, replace / *final output filename is testfile1.docx */
/* Final Note: Check your working directory for the result. You should be able to see the testfile1.docx */