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" <[email protected]>
To   <[email protected]>
Subject   st: RE: Help: typo-error in for-loop or more serious problem??
Date   Mon, 24 Feb 2003 16:31:43 +0100

Ernest,

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

Willard van Ooij
Marktmonitor BV
Postbus 377
3440 AJ Woerden
The Netherlands
tel. +31-(0)348-437391
e-mail:[email protected]


-----Oorspronkelijk bericht-----
Van: Ernest Berkhout [mailto:[email protected]]
Verzonden: maandag 24 februari 2003 15:28
Aan: [email protected]
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
'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
zero-value.
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' &
brinkort==`brinnr')
                 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
r(100)

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
http://www.seo.nl
=================================
"To an economist, real life is a special case"
=================================

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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