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: looping up to a local macro


From   Michael Costello <michaelavcostello@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: looping up to a local macro
Date   Wed, 22 Jun 2011 18:00:12 -0400

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/


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