THE
THE

Reputation: 3

Generating number sequence as a string in macro

Is there an easy way to generate a sequence in Stata like the R code:

seq(2000,2040, by=4) 

I have tried the following:

set obs 11 
egen seq = fill(2000, 2004)

However, I do not want to generate a variable. Instead, I want to generate just a string so that I can put it into a local macro.

For example:

local x 2000 2004 2008 2012 

Upvotes: 0

Views: 756

Answers (1)

user8682794
user8682794

Reputation:

You can do this with the numlist command:

. numlist "2000(4)2012"

. local x `r(numlist)'

. display "`x'"
2000 2004 2008 2012

See help numlist for full details.

Upvotes: 2

Related Questions