Liz's Stata Guide

Commands: Programming

This page covers basic commands for using Stata's programming features.

Most of the pages for commands in this category need to be written / rewritten

Repeats a block of code for multiple variables or values.
foreach var of varlist varx vary {;
    sum `var';

Defines a local macro.
ttest varx, by(groupvar);
local p = r(p);

if; else
Executes a command only if a certain condition is met. if (`p' < 0.5) display "significant";
else display "not significant";

Formats and displays text.
display as text "P-value for this test is" as result %5.4f `p'

last modified: 4 May 2007