* Author: Malcolm Wardlaw
* Majority credit to Nick Cox from Statalist post
* http://www.stata.com/statalist/archive/2008-04/msg00448.html
program listif
	version 8
	syntax [varlist(def=all)] [if/] [in/] [, * ]

	quietly {
		tempvar OK
		if `"`if'"' == "" local if 1
		gen byte `OK' = `if'
		replace `OK' = cond(`OK', sum(`OK'), 0)

		if "`in'" == "" {
			local first 1
			local last = _N
		}
		else {
			tokenize `in', parse("/")
			args first slash last
		}
	}

	list `varlist' if inrange(`OK', `first', `last'), `options'
end