Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: RE: looping up to a local macro


From   "Sarah Edgington" <sedging@ucla.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: looping up to a local macro
Date   Wed, 22 Jun 2011 15:20:25 -0700

Michael,
What do you mean by "I can't quite get it to work"?  What problem are you
having?
Without more information about what's going wrong it is really difficult to
offer much assistance.  The form of your loop looks fine.  Maybe there's
some problem with the code in the loop itself.  Does it work if you specify
a number instead of the local macro?  You're setting the value of letters in
the same dofile as the forvalues loop, right?  If you aren't that's going to
be a problem.

-Sarah
 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael Costello
Sent: Wednesday, June 22, 2011 3:00 PM
To: statalist
Subject: st: looping up to a local macro

Dear Statalisters;

I'm writing to ask about combining loops with local values.  I have a local
macro that I need to set equal to some value, different for each database.
 Let's say, for example, 50 in one db, 100 in another.  Then I want to
preform some loop operation on all the variables from
letter1 up to letter50 or letter100 (depending on the database).  Is that
possible, with some change to the code below?  I can't quite get it to work.

local letters 100

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
}

Basically, instead of copy ~400 lines of code into several dozen cleaning
files, I'd like to just set  the maximum value (50, 100, 20,
etc) for the database and have it run one cleaning file.  Thanks for any
help you can provide!
-Michael
--
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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index