HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Literate Stata #86

Open mcallaghan opened 8 years ago

mcallaghan commented 8 years ago

Hi all,

Sorry for posting this here but may be useful for those who have to return to Stata and are frustrated, and it's sort of relevant to using the principles of the course in other contexts.

I'm helping my boss prepare some materials for his Stats II lecture. Trying to find ways to get students towards a more reproducible approach, I wrote this little programme to try and do some terrible version of literate programming in Stata, without leaving Word for Latex.

You include Stata output by saving each section you want in a separate log file, then run the programme (Stata version of function) which you can install from the linked repository. This cleans up all the log files in a directory you point it to, getting rid of some unwanted text, and saves them as rtf files with some basic formatting options in the destination directory you point it to.

Working in word, you can insert these text files as links, so that when you run the analysis with some changes, you just have to refresh the word document's links (rather than copying and pasting again and forgetting some stuff and bla bla bla).

I think it's possibly useful, and possibly useful for some of you - so it would be great if people used it, and even greater if anyone tried it out and found bugs, difficulties or ideas for making it better, especially before I unleash it on first year students.

Incidently, another, better, way to do this kind of thing is Statweave. It's very nice, but uses latex like an rnw document, and I found it a bit of a pain to get set up properly. You also need admin rights, latex and Stata all on one computer, which for me is a rare combination.

Thanks!

christophergandrud commented 8 years ago

Thanks for posting.

I also think that you can specify engine='stata' in your knitr code chunk head. Though I've not tried this and it might take a bit of setting up.