I'm writing a program which uses display to mimic a list command. The user can enter an optional variable list. The problem: If the option is specified, but not used, it affects the displayed result. Here's a minimal example in which the goal is to list the makes of the first three cars in the auto data set. Compare the second and third set of results.
Code:
clear program drop _all program define llist syntax varname [, VARs(varlist min=1)] local listvar `1' tempvar id gen `id' = _n qui levelsof `id', local(ids) foreach i of local ids { di `listvar'[`i'] } end sysuse auto, clear keep in 1/3 . list make +-------------+ | make | |-------------| 1. | AMC Concord | 2. | AMC Pacer | 3. | AMC Spirit | +-------------+ . llist make AMC Concord AMC Pacer AMC Spirit . llist make, var(mpg) AMC Concord 1 AMC Concord 2 AMC Concord 3
Comment