Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Help: typo-error in for-loop or more serious problem??

From   Ernest Berkhout <>
Subject   st: Help: typo-error in for-loop or more serious problem??
Date   Mon, 24 Feb 2003 15:28:01 +0100

Hi all,

i was looking for a way to cycle through all the values of a particular
variable 'oplnr' without having to hardcode these values (they changes
every year). Walking through some faqs I come across the program 'vallist'
which should be able to do this for me. I integrated this in a small
foreach-loop program, but I get an errormessage that does not make sense to
me. As I'm not very experienced in programming Stata, it might be some
silly typo which I overlooked, but I cant see what is is. Or is there maybe
some other problem unknown to me?

The basic idea is to create a set of dummy-variables for interactions
between to variables oplnr & brinnr. But not all combinations are
meaningful in practice, so for reason of efficiency I want to drop all
dummies that indicate 'empty cells', that is for which all records have a
The program stores the values of a variable 'oplnr' in some macro `oplnr',
and then I introduce another loop which should cycle through a second set
of values (1 to 13) stored in the macro `brinnr'.
The following is the code that I've written:
gen temp=.
vallist oplnr
foreach oplnr of local r(list)  {
       forvalues brinnr = 1/13     {
                gen byte opXbr_`oplnr'_`brinnr' = (oplnr==`oplnr' &
                qui summ opXbr_`oplnr'_`brinnr', meanonly
                replace temp=r(max)
                if temp==0  drop opXbr_`oplnr'_`brinnr'
drop temp

The error message I get is:

{ required

Can someone please hint me what is wrong in my code? I do have 2 opening
and 2 closing brackets, why does that produce such an error?

Ernest Berkhout
Stichting voor Economisch Onderzoek
Universiteit van Amsterdam

De SEO is verhuisd! Tegenwoordig ben ik bereikbaar op:
Kamer 3.08
Roetersstraat 29
1018 WB Amsterdam

tel.:+ 31 20 525 1630
fax:+ 31 20 525 1686
"To an economist, real life is a special case"

*   For searches and help try:

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