11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

202 [ U ] 18 Programming StataStata programming is an advanced topic. Some Stata users live productive lives without everprogramming Stata. After all, you do not need to know how to program Stata to input data, createnew variables, and fit models. On the other hand, programming Stata is not difficult—at least if theproblem is not difficult—and Stata’s programmability is one of its best features. The real power ofStata is not revealed until you program it.If you are uncertain whether to read this chapter, we recommend that you start reading and thenbail out when it gets too arcane for you. You will learn things about Stata that you may find usefuleven if you never write a Stata program.If you want even more, we offer courses over the Internet on Stata programming; see [U] 3.7.1 Net-Courses. Baum (2009) provides a wealth of practical knowledge related to Stata programming.18.1 DescriptionWhen you type a command that Stata does not recognize, Stata first looks in its memory for aprogram of that name. If Stata finds it, Stata executes the program.There is no Stata command named hello,. hellounrecognized commandr(199);but there could be if you defined a program named hello, and after that, the following might happenwhen you typed hello:. hellohi there.This would happen if, beforehand, you had typed. program hello1. display "hi there"2. end.That is how programming works in Stata. A program is defined byprogram prognameStata commandsendand it is executed by typing progname at Stata’s dot prompt.18.2 Relationship between a program and a do-fileStata treats programs the same way it treats do-files. Below we will discuss passing arguments,consuming results from Stata commands, and other topics, but everything we say applies equally todo-files and programs.Programs and do-files differ in the following ways:1. You invoke a do-file by typing do filename. You invoke a program by simply typing theprogram’s name.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!