Archives for posts tagged ‘program’

Define local macros in one place, use them everywhere

In The Stata Journal Vol. 9, No. 3, 2009 there's a Stata tip (# 77) on re-using macros in multiple do-files, by Jeph Herrin. His solution is to define any local macros in a separate do-file, say locals.do. You can call that do-file with the include command at the top of any do-file that might [...]

The trouble with automatic type conversion

Lately I have been writing a lot of modular Stata code, where bits and pieces of the job are done by separate programs, sometimes declared in different do-files (called in with do). You get programs to pass on things to each other by making them rclass. Now, r() results can be scalars as in this [...]

Human-readable code

I just made a couple of changes to this theme's style sheet. I wanted a slightly wider page in order to accommodate longer lines of code. I needed it because some code lines in my Dummy variables post ran over when rendered in IE and Opera. If you cut and pasted the code, errant end-of-line [...]

Gems from the User’s Guide

A little over a year into my Stata 10 license, I can see some usage patterns over the two feet's worth of Stata documentation: Data Management and Programming are pretty well worn, the rest not so much. User's Guide,  [U], has been among the least popular, which is a pity, because chapter 18, Programming Stata, [...]

Arguments

In an older post I wrote about the program capability in Stata. One thing I didn't say and I find increasingly useful these days is that you can pass arguments to programs.
Packaging a set of commands inside a program, to be read once and then invoked as many times as they are needed, is nice [...]

Soup up your do-files: program

Most Stata commands are programs written in Stata's ado-file language; they are saved as .ado files that you are free to browse. For example, on my Windows XP machine the guts of the simple describe command are here: C:\Program Files\Stata10\ado\base\d\describe.ado.
Stata will let you write your own ado-files and treat them as first-class citizens of your [...]