Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Foreach loop for subsequent variables

From   daniel klein <>
Subject   Re: st: RE: Foreach loop for subsequent variables
Date   Tue, 1 Nov 2011 18:38:02 +0100


thanks for sharing this clever usage of -tokenize-. This might save
some typing in similar situations.

Here is another way, that might be faster, given the repeated useage
of -preserve- and -restore- in the codes given by Matt and Nick.

unab varlist : *
tokenize `varlist'

forv j = 1(2)897 {
	use ``j'' ``= `j' + 1'' using <filename>
	save `j'2


Matthew's code should work. This is an alternative:

unab varlist : *
tokenize `varlist'
forvalues i = 1(2)897 {
	local j = `i' + 1
	keep ``i'' ``j''
	save `i'2

But there is no important reason to use this code rather than Matthew's.
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index