Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: RE: looping up to a local macro
From
"Sarah Edgington" <[email protected]>
To
<[email protected]>
Subject
RE: st: RE: looping up to a local macro
Date
Thu, 23 Jun 2011 10:48:50 -0700
Michael,
It sounds like maybe there's a lot of code in the loop that you aren't
showing us. One thing that might be helpful is to -set trace on- right
before the chunk of code that's causing problems. That way you'll be able
to see exactly what line of code is tripping Stata up.
Do you get the invalid syntax message even if you run the loop without the
macro? For example, -forvalues i=1(1)50- ? If you do then the problem is
with something else in the code and my advice above should help you pinpoint
exactly what the issue is. If specifying a number instead of the local
macro letters solves the problem, that suggests that Stata doesn't recognize
the macro. Things you might check in that case are whether you've made a
mistake typing the name of the macro and whether you're setting the macro in
the same dofile you're calling it from. If you're testing things
interactively in Stata you'll need to set the macro before running the loop
even if you've done it previously in a dofile; Stata "forgets" all the local
macros as soon as a dofile completes.
-Sarah
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael Costello
Sent: Thursday, June 23, 2011 7:38 AM
To: [email protected]
Subject: Re: st: RE: looping up to a local macro
Wow, this became a much bigger thing than I was anticipating! Thanks for
all the interest though. I guess I'm wondering if I am thinking of the
local macro correctly, in that it's a kind of proxy for some value (in my
case 50, 100, etc) which can have operations done unto it, or if it's
something else that I don't understand.
I manage ~30 databases. Most of them need the same bits of code run on
them, but each has a different number of variables upon which that code must
be run. For example:
Database 1 has variables letter1, letter2, letter3, . . . , letter100
Database 2 has variables letter1, letter2, letter3, . . . , letter50
I would like to create this "master cleaning file" which, after establishing
a local macro value of either 50 or 100, would do the
following:
**Section: Letter Names**
egen letter_score2=rowtotal(letter1-letter`letters'), missing egen
letter_attempted=rownonmiss(letter1-letter`letters')
gen letter_score_pcnt=letter_score/`letters'
gen letter_score_zero= (letter_score==0) if letter_score<.
gen letter_attempted_pcnt=letter_score/letter_attempted
gen clpm=round(letter_score/(1-(letter_time_remain/60)))
But the error I'm getting is: "letter_sound ambiguous abbreviation"
for the first line of the code
Sarah, the error i'm getting when I try to run a loop is "invalid syntax"
forvalues i = 1(1)`letters' {
quietly: rename letter0`i' letter`i'
quietly: recode letter`i' (9=.) (2=1) (1=0)
* more lines of code here
}
invalid syntax
--
Michael Costello
"To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of." -Sir Ronald Aylmer Fisher, FRS
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/