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

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

From   "Willard van Ooij" <>
To   <>
Subject   st: RE: Help: typo-error in for-loop or more serious problem??
Date   Mon, 24 Feb 2003 16:31:43 +0100


I suspect you are using Stata version 7. The problem arises in the
if-programming command.
The line:

if temp==0  drop opXbr_`oplnr'_`brinnr'

doesn't work in versions prior tot Stata8. It requires braces.

if temp==0  {drop opXbr_`oplnr'_`brinnr'}

does work (but only in versions prior to 8).


Willard van Ooij
Marktmonitor BV
Postbus 377
3440 AJ Woerden
The Netherlands
tel. +31-(0)348-437391

-----Oorspronkelijk bericht-----
Van: Ernest Berkhout []
Verzonden: maandag 24 februari 2003 15:28
Onderwerp: st: Help: typo-error in for-loop or more serious problem??

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
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
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
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
The program stores the values of a variable 'oplnr' in some macro
and then I introduce another loop which should cycle through a second
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:
*   For searches and help try:

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