Haghish, E. F. (2014). Practical Stata Programming: Introduction to Stata Programming.
Updated on November 23th 2014

Introduction To Practical Stata Programming

| Quick Tips |     | Introduction |     | Mission |     | Sources for learning Stata programming |    

Quick Tips

Every Stata package offers a solution to a problem. But it also include the knowledge - computer codes - that how the problem was solved. Reading ado files can be as educative as taking Stata programming courses, if not more. In a series of articles, I will review several user-written Stata packages and by commenting them line-by-line, I will explain that what each part of the ado-file does. I hope that these articles motivate other Stata users to do the same and explain their own programs in details so that other Stata users can use and learn from their packages.


I learned Stata programming by reading other users' packages. Of course, Google, Statalist, and Stata manuals helped a lot to make sense of the commands, functions, etc. It was a very time consuming process but very rewarding because when you play with a published package there is one thing that you are sure about, which is the package works! And you should only find out how does it work. Furthermore, hacking into packages was the most fun part because I could make changes in the programs and change their behavior. But still, I was not able to write the whole program from scratch. I only could make sense of it, and sometimes hack into it and make some changes.

After a while, I began to make sense of chunks of codes. I learned that how multiple lines of codes relate one another and I could use them more effectively for problem solving. This skill came to be very helpful to me when I was authoring my packages. I could remember that a similar problem has been addressed in different packages (that I had fingered before), so I could get back to them and learn from them (and of course, whenever I copied a solution from a package, I noted that in the acknowledgment).

After authoring the Weaver package, I really felt that I should learn more about Stata programming. Then I enrolled into the Stata net courses. They were very helpful, explaining A-Z of Stata programming in a very simple way so that anyone could learn Stata programming. But still, the experience that I had gained from playing with published Stata packages, was way more fruitful because each package had to deal with some problems and I could see the solutions and the tricks that each author had come up with.


My main purpose for authoring these series of article which I categorize as "Practical Stata Programming" is twofold. First and formost, I would like to distribute the idea of doing literate programming while authoring a stata package. Authoring a new package is not just sharing a solution for solving a problem, but also is sharing the knowledge of solving the problem i.e. the programming solution. Doing literate programming allows other users to make sense of the codes and learn from the packages.

My second goal is to create an archive of user-written Stata packages that serves as a source for finding interesting Stata packages. This archive will not be used for installing Stata packages, but instead, it will be used for finding interesting packages and downloading ado files that interest you or are close to the package that you would like to develop.

In a series of articles, I will talk about the basics of writing a new package for Stata. I will also review several user-written packages for Stata and comment them to serve as a practical examples of authoring a Stata package as well as doing literate programming while authoring a new package.

I also intend

Sources for learning Stata programming

Stata manuals

STATA PROGRAMMING REFERENCE MANUAL as well as MATA REFERENCE MANUAL are what you start with before you do anything else. By reading these manuals carefully, you already are good to begin programming.

Programming Net Courses

Stata provides several affordable online courses. Check out NetCourse® schedules to find out about the courses that Stata currently is offering. For those who are interested in Stata programming, I recommend NC151: Introduction to Stata Programming as well as NC152: Advanced Stata Programming. The first course covers the basics but provides the required background for the advanced course. The introductory course is prepared for programming enthusiasts but not advanced users. Therefore, even if you have a little background about Stata, you will find the course easy but still very educative.

Online forums

Online forums such as Statalist and Stackoverflow are a good place to share questions. It is not a place to "learn programming", but instead, it's a place to ask your programming questions.

Stata programming book

An Introduction to Stata Programming, written by Christopher F. Baum, is the correct place to begin your way to Stata programming.
To view the table of the content of the book, go to this page and click on View table of contents >>