Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: looping up to a local macro

From   Michael Costello <>
To   statalist <>
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 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,

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index