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]
st: Loop over a list of strings with logs
From 
 
Brandon Olszewski <[email protected]> 
To 
 
[email protected] 
Subject 
 
st: Loop over a list of strings with logs 
Date 
 
Wed, 29 Jan 2014 11:56:27 -0800 
I am using Stata 12. I have a list of schools that I want to loop some
commands over, including logging output. I have consulted the
"Speaking Stata:  How to face lists with  fortitudeQ2/02   SJ
2(2):202--222" article and searched the list, but I am still
mystified. This is what I want to do:
I have a list of schools (var = school, string format), call them
"adams" "billings" and "charles". I want to perform the following
operations that will yield by school results: start a log that is
named for the respective school, keep observations only for one
school, display the school's name, tab responses to item1 and item2,
and close the log. I think it should be something like this:
foreach i in adams billings charles {
    preserve
    log using "C:\stata\`i'_results.txt, text replace
    keep if school==`i'
    di in r school
    tab item1
    tab item2
    log close
    restore
    }
I know I can also do something like:
local schools "adams billings charles"
foreach i in `schools' {
   preserve
   etc...
   }
When I try anything, Stata tells me that "adams not found".
I would really appreciate any help. I know I've done this before, but
just don't see what I'm doing wrong. Thanks.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/