Help importing Stata tables to Word

  • Thread starter Kurt Herman-Roloff
  • Start date
K

Kurt Herman-Roloff

Hi all -

I have been tasked with this problem and after doing some of my own
searches, was wondering if anyone had any suggestions on how best to
do this. I have a lot of Stata output (saved as a .txt file) and need
to get it into Word tables. I can pre-format the tables to have the
necessary font type, size, etc., but was hoping there was some way to
at least partially automate this process.

Here is some an example of some output:

Outlet Category | Freq. Percent Cum.
----------------+-----------------------------------
PHF | 505 6.72 6.72
Pharmacy/Clinic | 152 2.02 8.74
Drug store | 164 2.18 10.92
Mobile provider | 383 5.09 16.01
Grocery store | 1,170 15.56 31.58
Village shop | 5,144 68.42 100.00
----------------+-----------------------------------
Total | 7,518 100.00

Any ideas on how to get these into word tables, besides copying each
value and pasting them into the Word table?

Thanks much,
Kurt
 
S

Suzanne S. Barnhill

Assuming that each line of the table is a separate paragraph, search for
^p^w and replace with ^p, which will get rid of the extra spaces at the
beginnings of paragraphs (alternatively, you can just center them and then
switch back to left alignment). Use Replace to delete the pipe characters
and the lines with hyphens and pluses. Then search for ^w and replace with
^t, which will replace the spaces between items with a single tab. Then use
Table | Convert | Text to Table (or the equivalent in Word 2007/2010),
separating at tabs, to convert the text to a table. This will give you a
table with four columns and as many rows as you have paragraphs, to which
you can then apply the desired formatting.

If by "automate" you mean that you want to accomplish all the above via VBA,
then I have no doubt it is possible, but someone else will have to tell you
how to do it.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
Top