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

st: RE: creating a varlist

From   "Nick Cox" <>
To   <>
Subject   st: RE: creating a varlist
Date   Wed, 22 Oct 2008 19:56:30 +0100

Zap the equals sign. With it you force evaluation and do get bitten by
the limit on the length of a string expression. 

Incidentally the -egen- function is redundant if you are looping any

gen ttt = 0 
qui forval n = 5/46 { 
	replace ttt = ttt + (q`n'3_1 == 1) 
	replace ttt = ttt + (q`n'3_2 == 1)


Radu Ban

I want to generate a variable with the -egen anycount- command.

let's say:

egen ttt = anycount(`vlist'), v(1)

The varlist in the argument is long and the variables have some
regularity in their names. They all of the form qX3_1 qX3_2, where X
goes from 5 to 46. Note that there are other variables with X between
1 and 4 which I do not want, so that a varlist q*3_1 q*3_2 does not
work. To create my variables list I did the following:

local vlist ""
forvalues n = 5/46 {
	local vlist = "`vlist' q`n'3_1 q`n'3_2"
*then to check
di "`vlist'"

However, the display command shows that the macro stops at q23. Am I
running into a limit here? I checked help limits and the limit to
number of characters in a macro is way higher ( 1,081,511 in Stata
SE). If indeed there is a limit, can anyone point out a work around?

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index