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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: looping up to a local macro


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: looping up to a local macro
Date   Wed, 22 Jun 2011 22:51:45 +0000

<>

Change your -rename- line to:    quietly: cap rename letter0`i' letter`i'   

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu



On Jun 22, 2011, at 5:00 PM, Michael Costello wrote:

> 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